Netty websocket配置wss

录音配置https 导致ws连不上

java 复制代码
@Slf4j
@Component
public class NettyServer {

    /**
     * 启动
     *
     * @throws InterruptedException
     */
    private void start() throws InterruptedException {
        bossGroup = new NioEventLoopGroup();
        workGroup = new NioEventLoopGroup();
        ServerBootstrap bootstrap = new ServerBootstrap();
        // bossGroup辅助客户端的tcp连接请求, workGroup负责与客户端之前的读写操作
        bootstrap.group(bossGroup, workGroup);
        // 设置NIO类型的channel
        bootstrap.channel(NioServerSocketChannel.class);
        // 设置监听端口
        bootstrap.localAddress(new InetSocketAddress(port));
        // 连接到达时会创建一个通道
        bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {

            @Override
            protected void initChannel(SocketChannel ch) throws Exception {
               // 添加SSL处理器
                FileInputStream crt = new FileInputStream("/etc/app/ssl/test.xx-zn.com_bundle.crt");
                FileInputStream key = new FileInputStream("/etc/app/ssl/test.xx-zn.com.key");
                SslContext sslContext = SslContextBuilder.forServer(crt, key)
                        .sslProvider(SslProvider.JDK)
                        .build();
                ch.pipeline().addLast(sslContext.newHandler(ch.alloc()));
               
    }

https 和wss用的是同一个域名证书(企鹅),Java 配置WSS ssl处理器,启动程序发现报错

无法找ssl文件的key,发现格式不匹配。下载openssl转 ssl文件中.key 到pkcs8格式

openssl工具下载地址:

Win32/Win64 OpenSSL Installer for Windows - Shining Light Productionsp

配置openssl环境变量,win path 后面加安装目录 D:\zhang\OpenSSL-Win64\bin

打开cmd 执行openssl pkcs8 -topk8 -nocrypt -in 你的.key文件 -out pkcs8.key

备注:ssl证书给的.key文件就是pkcs1格式文件

相关推荐
是小满满满满吗8 小时前
传输层:udp与tcp协议
linux·服务器·网络
小刘同学++8 小时前
ECB(电子密码本,Electronic Codebook) 和 CBC(密码分组链接,Cipher Block Chaining)区分于用途
网络·ssl
CryptoPP8 小时前
使用WebSocket实时获取印度股票数据源(无调用次数限制)实战
后端·python·websocket·网络协议·区块链
gadiaola9 小时前
【计算机网络】第3章:传输层—TCP 拥塞控制
网络·网络协议·tcp/ip·计算机网络
猎板PCB厚铜专家大族9 小时前
多层PCB技术解析:从材料选型到制造工艺的深度实践
网络·制造
FakeOccupational11 小时前
【碎碎念】宝可梦 Mesh GO : 基于MESH网络的口袋妖怪 宝可梦GO游戏自组网系统
网络·游戏
fei_sun13 小时前
【计算机网络】三报文握手建立TCP连接
网络·tcp/ip·计算机网络
Johny_Zhao13 小时前
2025年6月Docker镜像加速失效终极解决方案
linux·网络·网络安全·docker·信息安全·kubernetes·云计算·containerd·yum源·系统运维
PypYCCcccCc13 小时前
支付系统架构图
java·网络·金融·系统架构
廖致君14 小时前
C/Python/Go示例 | Socket Programing与RPC
网络协议