5. 加密通信插件🛡
# 准备SSL证书
执行以下命令生成证书
keytool -genkey -validity 36000 -alias www.smartboot.org -keyalg RSA -keystore server.keystore
1
# 示例
完整示例见:SslDemo (opens new window)
# 服务端配置
ServerSSLContextFactory serverFactory = new ServerSSLContextFactory(SslDemo.class.getClassLoader().getResourceAsStream("server.keystore"), "123456", "123456");
SslPlugin sslServerPlugin = new SslPlugin(serverFactory, ClientAuth.OPTIONAL);
serverProcessor.addPlugin(sslServerPlugin);
1
2
3
2
3
# 客户端配置
ClientSSLContextFactory clientFactory=new ClientSSLContextFactory();
SslPlugin sslPlugin = new SslPlugin(clientFactory);
clientProcessor.addPlugin(sslPlugin);
1
2
3
2
3