Netty 官方支持 SSL 验证,并自带有实例代码,下面代码示例基本源自官方 demo:
1.服务端
package com.learn.netty.ssl;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.util.SelfSignedCertificate;
import java.net.InetSocketAddress;
public class EchoServer {
public static void main(String[] args) throws Exception {
SelfSignedCertificate ssc = new SelfSignedCertificate();
SslContext sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();

本文介绍了如何在 Netty 中实现 SSL 验证,提供了服务端和客户端的示例代码,帮助读者理解 Netty 的 SSL 配置与验证过程。
最低0.47元/天 解锁文章
3104

被折叠的 条评论
为什么被折叠?



