当前位置: 首页 > news >正文

哈尔滨市土地局做seo的网站

哈尔滨市土地局,做seo的网站,网站系统问题解决措施,建设银行网站不主动弹出“不积跬步#xff0c;无以至千里。” 说明 其实Netty使用SslHandler实现加密通信单向认证和双向认证在代码上区别不大#xff0c;下面是双向认证的代码示例 引入依赖 dependencygroupIdio.netty/groupIdartifactIdnetty-all/artifac… “不积跬步无以至千里。” 说明 其实Netty使用SslHandler实现加密通信单向认证和双向认证在代码上区别不大下面是双向认证的代码示例 引入依赖 dependencygroupIdio.netty/groupIdartifactIdnetty-all/artifactIdversion4.1.100.Final/version /dependency生成keystore.jks文件 keytool -genkeypair -alias your_alias -keyalg RSA -keystore keystore.jks -keysize 2048Server端 import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.*; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.ssl.SslHandler; import io.netty.util.CharsetUtil;import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; import java.io.FileInputStream; import java.nio.charset.StandardCharsets; import java.security.KeyStore;public class NettySslServer {private static final int PORT 8888;public static void main(String[] args) throws Exception {// 加载SSL证书String serverKeyStorePath /home/admin/server/keystore.jks;String clientKeyStorePath /home/admin/client/keystore.jks;String serverKeyStorePassword happya;String clientKeyStorePassword happya;// 创建SSL上下文SSLContext sslContext SSLContext.getInstance(TLS);sslContext.getServerSessionContext().setSessionCacheSize(1);sslContext.getServerSessionContext().setSessionTimeout(60);// 配置密钥库KeyStore keyStore KeyStore.getInstance(JKS);keyStore.load(new FileInputStream(serverKeyStorePath), serverKeyStorePassword.toCharArray());KeyManagerFactory keyManagerFactory KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());keyManagerFactory.init(keyStore, serverKeyStorePassword.toCharArray());// 配置信任库KeyStore trustStore KeyStore.getInstance(JKS);trustStore.load(new FileInputStream(clientKeyStorePath), clientKeyStorePassword.toCharArray());TrustManagerFactory trustManagerFactory TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());trustManagerFactory.init(trustStore);// 初始化SSLContextsslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);// 创建EventLoopGroupEventLoopGroup bossGroup new NioEventLoopGroup();EventLoopGroup workerGroup new NioEventLoopGroup();try {// 创建服务器BootstrapServerBootstrap serverBootstrap new ServerBootstrap();serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializerSocketChannel() {Overrideprotected void initChannel(SocketChannel ch) throws Exception {ChannelPipeline pipeline ch.pipeline();// 在ChannelPipeline中添加SSL处理器SSLEngine sslEngine sslContext.createSSLEngine();sslEngine.setUseClientMode(false);pipeline.addLast(new SslHandler(sslEngine));// 添加加密通信处理器pipeline.addLast(new SecureChatServerHandler());}}).childOption(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);// 启动服务器System.out.println(Begin to start ssl server);ChannelFuture future serverBootstrap.bind(PORT).sync();System.out.println(Ssl server started);future.channel().closeFuture().sync();} finally {workerGroup.shutdownGracefully();bossGroup.shutdownGracefully();}}public static class SecureChatServerHandler extends ChannelInboundHandlerAdapter {Overridepublic void channelActive(ChannelHandlerContext ctx) throws Exception {// 当连接建立时发送欢迎消息System.out.println(Server channel active : ctx.channel().toString());ctx.channel().writeAndFlush(Unpooled.wrappedBuffer(Welcome to the secure chat server!\n.getBytes(StandardCharsets.UTF_8)));ctx.channel().writeAndFlush(Unpooled.wrappedBuffer(Your connection is protected by SSL.\n.getBytes(StandardCharsets.UTF_8)));}Overridepublic void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {ByteBuf byteBuf (ByteBuf) msg;System.out.println(Server received message: byteBuf.toString(CharsetUtil.UTF_8));super.channelRead(ctx, msg);}Overridepublic void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {// 处理异常cause.printStackTrace();ctx.close();}} }Client端 import io.netty.bootstrap.Bootstrap; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.*; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.ssl.SslHandler; import io.netty.util.CharsetUtil;import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; import javax.net.ssl.TrustManagerFactory; import java.io.FileInputStream; import java.nio.charset.StandardCharsets; import java.security.KeyStore;public class NettySslClient {private static final String HOST localhost;private static final int PORT 8888;public static void main(String[] args) throws Exception {// 加载SSL证书String serverKeyStorePath /home/admin/server/keystore.jks;String clientKeyStorePath /home/admin/client/keystore.jks;String serverKeyStorePassword happya;String clientKeyStorePassword happya;// 创建SSL上下文SSLContext sslContext SSLContext.getInstance(TLS);sslContext.getServerSessionContext().setSessionCacheSize(1);// session cache timeout (sessionTimeout) s default value is 86400s (24hr), and reduced to 60s to reduce IO block issue.sslContext.getServerSessionContext().setSessionTimeout(60);// 配置密钥库KeyStore keyStore KeyStore.getInstance(JKS);keyStore.load(new FileInputStream(clientKeyStorePath), clientKeyStorePassword.toCharArray());KeyManagerFactory keyManagerFactory KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());keyManagerFactory.init(keyStore, clientKeyStorePassword.toCharArray());// 配置信任库KeyStore trustStore KeyStore.getInstance(JKS);trustStore.load(new FileInputStream(serverKeyStorePath), serverKeyStorePassword.toCharArray());TrustManagerFactory trustManagerFactory TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());trustManagerFactory.init(trustStore);sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);// 创建EventLoopGroupEventLoopGroup group new NioEventLoopGroup();try {// 创建客户端BootstrapBootstrap bootstrap new Bootstrap();bootstrap.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializerSocketChannel() {Overrideprotected void initChannel(SocketChannel ch) throws Exception {ChannelPipeline pipeline ch.pipeline();// 在ChannelPipeline中添加SSL处理器SSLEngine sslEngine sslContext.createSSLEngine();sslEngine.setUseClientMode(true);pipeline.addLast(new SslHandler(sslEngine));// 添加加密通信处理器pipeline.addLast(new SecureChatClientHandler());}});// 连接服务器System.out.println(Begin to start ssl client);ChannelFuture future bootstrap.connect(HOST, PORT).sync();System.out.println(Ssl client started);future.channel().closeFuture().sync();} finally {group.shutdownGracefully();}}public static class SecureChatClientHandler extends ChannelInboundHandlerAdapter {Overridepublic void channelActive(ChannelHandlerContext ctx) throws Exception {// 连接建立时发送一条消息给服务器System.out.println(Client channel active : ctx.channel().toString());ctx.channel().writeAndFlush(Unpooled.wrappedBuffer(Hello from client!\n.getBytes(StandardCharsets.UTF_8)));}Overridepublic void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {ByteBuf byteBuf (ByteBuf) msg;System.out.println(Client received message: \n byteBuf.toString(CharsetUtil.UTF_8));super.channelRead(ctx, msg);}Overridepublic void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {// 处理异常cause.printStackTrace();ctx.close();}} }
http://www.pierceye.com/news/698603/

相关文章:

  • 怎么可以创建网站体育设施建设网站
  • 中航建设集团网站wordpress实现分页
  • 企业网站现状舟山seo网络优化招聘
  • 棋牌网站开发工程师网络彩票建立网站
  • 上海正规建设网站私人订制网站建设中 显示
  • 网站建设广告宣传素材论坛网站制作教程
  • 苏州怎么做网站如何做公司自己的网站
  • 网站内容通过服务器会不会被更改旅游网站建设流程是什么意思
  • 建立中文网站的英文免费网站空间
  • 外国人做家具的网站免费自己做网站软件
  • 品牌网站建设毛尖2新加坡二手手机网站大全
  • 服装集团网站建设wordpress rss格式
  • 如何进行网站分析设计说明的英文
  • 仕德伟做的网站图片怎么修做网站深圳
  • 六安电商网站建设哪家好中国电力工程造价信息网
  • 如何做优化网站排alexa优化装修网线
  • 现在视频做网站晚了吗做网站的论文摘要
  • 环保公司网站模板那个公司可以做网站
  • 英雄联盟网站源码开发设计公司
  • 企业形象网站开发名师工作室网站建设
  • o2o网站建设最好公司排名做竹鼠网站
  • 免费做网站软件2003商丘网络营销服务
  • 杭州网站建设加q479185700如何网上外贸接单
  • 针对茅台酒企业网站建设方案鸿基建设工程有限公司网站
  • 有创意营销型网站建设wordpress 慢集市
  • 注册网站多少钱永康电子商务网站建设
  • 江西省网站建设庆阳在线网
  • wordpress建站微信联系智慧政务网站怎么做
  • 邯郸购物网站建设电子商务是干什么的工作
  • 网站开发竞聘报告wordpress彩色标签云设置方法