{"id":54,"date":"2023-10-17T12:10:06","date_gmt":"2023-10-17T04:10:06","guid":{"rendered":"https:\/\/bbstone.cn\/?p=54"},"modified":"2026-05-11T14:24:39","modified_gmt":"2026-05-11T06:24:39","slug":"java%e5%a4%a7%e6%96%87%e4%bb%b6%e4%bc%a0%e8%be%93%ef%bc%88netty%e5%ba%94%e7%94%a8%e4%b8%80%ef%bc%89","status":"publish","type":"post","link":"https:\/\/bbstone.cn\/?p=54","title":{"rendered":"Java\u5927\u6587\u4ef6\u4f20\u8f93\uff08Netty\u5e94\u7528\u4e00\uff09"},"content":{"rendered":"\n<h2 class=\"wp-block-heading has-text-align-left\"><strong>\u8bf4\u660e<\/strong><\/h2>\n\n\n\n<p>\u57fa\u4e8eNetty\u7684FileRegion\u6a21\u5f0f\u548cChunkedFile\u6a21\u5f0f\u5b9e\u73b0\u7684\u5927\u6587\u4ef6\u4f20\u8f93demo\uff0c\u5176\u4e2dChunkedFile\u4f7f\u7528\u4e86SSL\u3002<\/p>\n\n\n\n<p>\u7531\u4e8e\u6700\u8fd1\u60f3\u5728\u4e24\u53f0\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u7684\u7535\u8111\u4e4b\u95f4\u4f20\u8f93\u8f83\u5927\u7684\uff083G\u5de6\u53f3\uff09\u5355\u4e2a\u5927\u6587\u4ef6\u7684\u9700\u8981\uff0c\u4e8e\u662f\u7528netty\u81ea\u5df1\u5199\u4e2a\u6587\u4ef6\u4f20\u8f93\u7684\u5b8c\u6574demo\u3002\uff08\u5f53\u7136\u53ef\u4ee5\u901a\u8fc7U\u76d8\u6216\u79fb\u52a8\u786c\u76d8\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u8fd9\u4e2a\u9700\u6c42\uff09<\/p>\n\n\n\n<p>\u4ecenetty\u7684\u5b98\u65b9\u6587\u4ef6\u4f20\u8f93\u7684example\u4e2d\u53c2\u8003\u4e86server\u7aef\u7684\u5b9e\u73b0\uff0c\u4f46\u662f\u6ca1\u6709\u627e\u5230\u5ba2\u6237\u7aef\u7684\u4f8b\u5b50\u6765\u8fd0\u884c\u7a0b\u5e8f\uff0c\u4e8e\u662f\u81ea\u5df1\u5199\u4e86\u4e2a\u53d1\u5230gitee\u4e0a(<a href=\"https:\/\/links.jianshu.com\/go?to=https%3A%2F%2Fgitee.com%2Fbbstone101%2Fpisces.git\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/gitee.com\/bbstone101\/pisces.git<\/a>)\u3002<\/p>\n\n\n\n<p>Netty\u6e90\u7801\u4e2d\u7684\u6587\u4ef6\u4f20\u8f93example\u7684\u8def\u5f84\uff1a\/netty-4.1.48.Final\/example\/src\/main\/java\/io\/netty\/example\/file<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Bootstrap\u7f16\u7801\u89e3\u7801\u8fc7\u7a0b\u8bf4\u660e<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Server Bootstrap\u4f7f\u7528\u7684channel handler\u8bf4\u660e\uff1a<\/strong><\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>ServerBootstrap b = new ServerBootstrap();\n  b.group(bossGroup, workerGroup)\n   .channel(NioServerSocketChannel.class)\n   .option(ChannelOption.SO_BACKLOG, 100)\n   .handler(new LoggingHandler(LogLevel.INFO))\n   .childHandler(new ChannelInitializer&lt;SocketChannel&gt;() {\n      @Override\n      public void initChannel(SocketChannel ch) throws Exception {\n        ChannelPipeline p = ch.pipeline();\n        if (sslCtx != null) {\n          p.addLast(sslCtx.newHandler(ch.alloc()));\n        }\n        \/\/ outbound (default ByteBuf)\n        \/\/ no encoder, direct send ByteBuf\n        \/\/ if os not support zero-copy, used ChunkedWriteHandler\n        p.addLast(new ChunkedWriteHandler());\n        \/\/ inbound(decode by the delimiter, then forward to protobuf decoder, last forward to handler)\n        ByteBuf delimiter = Unpooled.copiedBuffer(ConstUtil.delimiter.getBytes(CharsetUtil.UTF_8));\n        p.addLast(new DelimiterBasedFrameDecoder(8192, delimiter)); \/\/ frameLen = BFileReq bytes\n        p.addLast(new ProtobufDecoder(BFileMsg.BFileReq.getDefaultInstance()));\n        p.addLast(new FileServerHandler());\n      }\n});\n<\/code><\/pre>\n<\/blockquote>\n\n\n\n<p>Server\u7aefoutbound\uff08\u53d1\u9001\u51fa\u53bb\uff09\u4f7f\u7528\u4e86ChunkedWriteHandler,\u5728chunkedFile \u6a21\u5f0f\u4e0b\u7528\u5230\uff08FileRegion\u6a21\u5f0f\u4f1a\u8df3\u8fc7\u6b64handler\uff09\uff0cChunkedFile\u4f1a\u7ecf\u8fc7ChunkedWriteHandler\u6765\u4e00\u5757\u4e00\u5757\u53d1\u9001\u6587\u4ef6\u6570\u636e\u3002<\/p>\n\n\n\n<p>Inbound\uff08\u63a5\u6536\u4f20\u5165\uff09\u7684\u6570\u636e\u6d41\u7ecf\u8fc7\u81ea\u5b9a\u4e49\u7684delimiter\u89e3\u7801\uff0c<\/p>\n\n\n\n<p>\u7136\u540e\u518d\u7ecf\u8fc7protobuf\u89e3\u7801\u540e\uff0c<\/p>\n\n\n\n<p>\u6700\u540e\u4f20\u9012\u7ed9FileServerHandler\u8bfb\u53d6\u8bf7\u6c42\u7684\u6587\u4ef6\u6216\u76ee\u5f55\uff0c\u8fd4\u56de\u6587\u4ef6BFileInfo\u5217\u8868\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Client Bootstrap\u4f7f\u7528\u7684channel handler\u8bf4\u660e\uff1a<\/strong><\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>Bootstrap b = new Bootstrap();\nb.group(group)\n .channel(NioSocketChannel.class)\n .option(ChannelOption.TCP_NODELAY, true)\n .handler(new ChannelInitializer&lt;SocketChannel>() {\n    @Override\n    public void initChannel(SocketChannel ch) throws Exception {\n      ChannelPipeline p = ch.pipeline();\n      if (sslCtx != null) {\n        p.addLast(sslCtx.newHandler(ch.alloc()));\n      }\n      \/\/ outbound(BFileReq)\n      p.addLast(new ProtobufEncoder());\n\n      \/\/ --- inbound\n      \/\/ if os not support zero-copy\/sslEnabled, used this, must be the first inbound handler\n      p.addLast(new ChunkedReadHandler());\n\n      \/\/ ----- decode and handle (BFileRsp + FileRegion) data stream\n      ByteBuf delimiter = Unpooled.copiedBuffer(ConstUtil.delimiter.getBytes(CharsetUtil.UTF_8));\n      \/\/ inbound frameLen = chunkSize&#91;default: 8192] + BFileRsp header)\n\/\/    p.addLast(new DelimiterBasedFrameDecoder(10240, delimiter));\n      p.addLast(new DelimiterBasedFrameDecoder(Integer.MAX_VALUE, delimiter));\n      p.addLast(new FileClientHandler());\n   }\n});<\/code><\/pre>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u8bf7\u6c42\u5934\u548c\u54cd\u5e94\u5934<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u8bf7\u6c42\u5934\u6d88\u606f\u683c\u5f0f-protobuf\uff08\u7531client\u7aef\u7f16\u7801\uff0cserver\u7aef\u89e3\u7801\uff09<\/strong><\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>message BFileReq{\n    string id = 1;\n    string cmd = 2;\n    string filepath = 3;\n    \n    uint64 ts = 4;\n}<\/code><\/pre>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u54cd\u5e94\u5934\u6d88\u606f\u683c\u5f0f-protobuf\uff08\u7531server\u7aef\u7f16\u7801\uff0cclient\u7aef\u89e3\u7801\uff09<\/strong><\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>message BFileRsp{\n    string id = 1;\n    string cmd = 2;\n    string filepath = 3;\n\n    uint64 fileSize = 4;\n    string checksum = 5;\n    string rspData = 6;\n    bytes chunkData = 7;\n\n    uint64 reqTs = 8;\n    uint64 rspTs = 9;\n}<\/code><\/pre>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u6d88\u606f\u683c\u5f0f\u8bf4\u660e\uff1a<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u6587\u4ef6\u8bf7\u6c42\u7684\u6d88\u606f\u683c\u5f0f<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">REQ_FILE \u8bf7\u6c42\u6307\u4ee4\u7684\u6d88\u606f\u683c\u5f0f<\/h4>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>----------------------+\n| BFileReq| delimiter |\n----------------------+<\/code><\/pre>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u6587\u4ef6\u54cd\u5e94\u7684\u6d88\u606f\u683c\u5f0f\uff08FileRegion\u6a21\u5f0f\uff09<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">RSP_FILE \u54cd\u5e94\u6307\u4ee4\u7684\u6d88\u606f\u683c\u5f0f<\/h4>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>------------------------------------+\n| BFileRsp | chunk_data | delimiter |\n------------------------------------+<\/code><\/pre>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">\u6587\u4ef6\u54cd\u5e94\u7684\u6d88\u606f\u683c\u5f0f\uff08ChunkedFile\u6a21\u5f0f\uff09<\/h3>\n\n\n\n<p>\u7b2c\u4e00\u6761\u662f\u6587\u4ef6\u4fe1\u606f\u7684\u6d88\u606f\uff0c\u6709\u754c\u5b9a\u7b26\uff08\u89e3\u51b3\u7c98\u5305\u548c\u62c6\u5305\u95ee\u9898\uff09<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>----------------------+\n| BFileRsp| delimiter |\n----------------------+<\/code><\/pre>\n<\/blockquote>\n\n\n\n<p>\u7b2c\u4e8c\u6761\u662fChunkedFile\u7ecf\u8fc7ChunkedWriteHandler\u6309\u7167\u4e00\u5757\u5757\u53d1\u9001\u7684\u6570\u636e\uff0c\u6ca1\u6709\u754c\u5b9a\u7b26\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>-------------+\n| chunk_data |\n-------------+<\/code><\/pre>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u6587\u4ef6\u4f20\u8f93\u8bf7\u6c42-\u54cd\u5e94 \u8fc7\u7a0b\u8bf4\u660e<\/strong><\/h2>\n\n\n\n<p>\u7531client\u7aef\u89e6\u53d1\u64cd\u4f5c\uff0cclient\u8fde\u4e0aserver\u540e\uff0c\u53d1\u8d77\u67e5\u8be2\u6587\u4ef6\u5217\u8868\u8bf7\u6c42\uff0cserver\u5c06\u6307\u5b9a\u7684\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6BFileInfo\u5217\u8868\u8fd4\u56de\u7ed9client\u7aef\u3002<\/p>\n\n\n\n<p>client\u7aef\u6536\u5230\u5217\u8868\u540e\uff0c\u6839\u636e\u5217\u8868\u9010\u4e2a\u53d1\u8d77\u6587\u4ef6\u4e0b\u8f7d\u8bf7\u6c42\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>FileRegion\u6a21\u5f0f\uff1a<\/strong><\/h3>\n\n\n\n<p>server\u7aef\u901a\u8fc7FileRegion\u5c06\u6587\u4ef6\u5207\u5272\u62108192 Byte\u5927\u5c0f\u7684chunk\uff0c\u9010\u4e2a\u5199\u5230channel\u4e2d\u3002\u6bcf\u4e2achunk\u90fd\u9644\u52a0\u4e0aBFileRsp\u7684\u54cd\u5e94\u5934\u4fe1\u606f\u3002\uff08\u8be6\u7ec6\u683c\u5f0f\u89c1 \u8bbe\u8ba1\u8bf4\u660e RSP_FILE \u6307\u4ee4\u7801\u683c\u5f0f \u7ae0\u8282\uff09<\/p>\n\n\n\n<p>client\u7aef\u6536\u5230\u6d88\u606f\u540e\uff0c\u8fdb\u884c\u89e3\u7801\uff0c\u5148\u89e3\u51faBFileRsp\u7684\u5934\u4fe1\u606f\uff0c\u7136\u540e\u6839\u636e\u5934\u4fe1\u606f\u7684\u6307\u4ee4\u7801\uff08cmd\uff09\uff0c\u9009\u62e9\u5bf9\u5e94\u7684CmdHandler\u6765\u5904\u7406\u6d88\u606f\u3002\u4e3a\u4e86\u51cf\u5c11\u9891\u7e41\u5199\u78c1\u76d8\uff0cclient\u6536\u5230chunk\u540e\uff0c\u5148\u7f13\u5b58\u8d77\u6765\uff0c\u76f4\u5230\u7f13\u5b58\u6ee14M\u6216\u6587\u4ef6\u6570\u636e\u63a5\u6536\u5b8c\u6bd5\u540e\u624d\u5199\u4e00\u6b21\u6587\u4ef6\u6570\u636e\u5230\u78c1\u76d8\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>ChunkedFile\u6a21\u5f0f\uff1a<\/strong><\/h3>\n\n\n\n<p>server\u7aef\u9996\u5148\u53d1\u9001\u4e00\u6761BFileRsp\u7ed3\u6784\u7684\u6587\u4ef6\u4fe1\u606f\uff08\u5305\u62eccmd\uff0c\u6587\u4ef6\u76f8\u5bf9server.dir\u7684\u8def\u5f84\uff0cchecksum\u7b49\u4fe1\u606f\uff09\u3002\u7136\u540e\u63a5\u7740\u53d1\u9001ChunkedFile\u3002<\/p>\n\n\n\n<p>client\u7aef\u6536\u5230\u54cd\u5e94\u540e\uff0c\u9996\u5148\u89e3\u6790\u7b2c\u4e00\u6761BFileRsp\u7684\u6d88\u606f\uff0c\u89e3\u6790\u540e\uff0c\u5982\u679c\u662fRSP_FILE\u547d\u4ee4\uff0c\u5c31\u7ed9ClientCache.recvFileKey\u8d4b\u503c\uff0c\u5e76\u4fdd\u5b58\u63a5\u6536\u5230\u7684BFileRsp\u4fe1\u606f\u3002\u7b2c\u4e8c\u6761\u6d88\u606f\u5f00\u59cb\u5c31\u662fchunked file\u7684\u7eaf\u6587\u4ef6\u6570\u636e\uff08\u5177\u4f53\u53d1\u9001\u591a\u5c11\u5b57\u8282\u6570\u636e\u7531ChunkedWriteHandler\u51b3\u5b9a\uff09\u3002\u6587\u4ef6\u63a5\u6536\u5b8c\u6210\u540e\uff0c\u91cd\u7f6erecvFileKey\u4e3anull\uff0c\u5220\u9664\u7b2c\u4e00\u6761\u6d88\u606f\u4fdd\u5b58\u7684BFileRsp\u7684\u6587\u4ef6\u4fe1\u606f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5df2\u77e5\u95ee\u9898<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u65ad\u70b9\u7eed\u4f20\u529f\u80fd\u672a\u5b9e\u73b0<\/li>\n\n\n\n<li>client\u7aef\u63a5\u6536\u6587\u4ef6\u7684\u76ee\u5f55\u5982\u679c\u5df2\u7ecf\u6709\u4e00\u6837\u7684\u6587\u4ef6\uff0c\u4f1a\u76f4\u63a5\u8986\u76d6\uff0c\u4e0d\u4f1a\u8df3\u8fc7\u3002<\/li>\n\n\n\n<li>server\u7aef\u4e0b\u8f7d\u6587\u4ef6\u7684\u76ee\u5f55\u548cclient\u7aef\u63a5\u6536\u6587\u4ef6\u7684\u76ee\u5f55\u53ea\u80fd\u901a\u8fc7config.propertis\u9884\u5148\u914d\u7f6e\u597d\uff0c\u8fd8\u4e0d\u652f\u6301\u901a\u8fc7\u547d\u4ee4\u4ea4\u4e92\u65b9\u5f0f\u8f93\u5165\u6e90\u6587\u4ef6\u8def\u5f84\u548c\u4fdd\u5b58\u7684\u76ee\u6807\u8def\u5f84\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u9644\u5f55\uff1aSSL\u4e2d\u4f7f\u7528\u7684\u6570\u5b57\u8bc1\u4e66\u521b\u5efa\u8fc7\u7a0b<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u57fa\u672c\u6d41\u7a0b<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u641e\u4e00\u4e2a\u865a\u62df\u7684CA\u673a\u6784\uff0c\u751f\u6210\u4e00\u4e2a\u8bc1\u4e66<\/li>\n\n\n\n<li>\u751f\u6210\u4e00\u4e2a\u81ea\u5df1\u7684\u5bc6\u94a5\uff0c\u7136\u540e\u586b\u5199\u8bc1\u4e66\u8ba4\u8bc1\u7533\u8bf7\uff0c\u62ff\u7ed9\u4e0a\u9762\u7684CA\u673a\u6784\u53bb\u7b7e\u540d<\/li>\n\n\n\n<li>\u4e8e\u662f\u5c31\u5f97\u5230\u4e86\u81ea\uff08\u81ea\u5efaCA\u673a\u6784\u8ba4\u8bc1\u7684\uff09\u7b7e\u540d\u8bc1\u4e66<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Server\/Client\u90fd\u7528ca.crt\u6765\u7b7e\u540d<\/strong><\/h3>\n\n\n\n<p>\u9996\u5148\uff0c\u865a\u6784\u4e00\u4e2aCA\u8ba4\u8bc1\u673a\u6784\u51fa\u6765<\/p>\n\n\n\n<p>\u751f\u6210CA\u8ba4\u8bc1\u673a\u6784\u7684\u8bc1\u4e66\u5bc6\u94a5key# \u9700\u8981\u8bbe\u7f6e\u5bc6\u7801\uff0c\u8f93\u5165\u4e24\u6b21(123456)<\/p>\n\n\n\n<p>openssl genrsa -des3 -out ca.key 1024<\/p>\n\n\n\n<p>\u53bb\u9664\u5bc6\u94a5\u91cc\u7684\u5bc6\u7801(\u53ef\u9009)# \u8fd9\u91cc\u9700\u8981\u518d\u8f93\u5165\u4e00\u6b21\u539f\u6765\u8bbe\u7684\u5bc6\u7801<\/p>\n\n\n\n<p>openssl rsa -in ca.key -out ca.key<\/p>\n\n\n\n<p>\u7528\u79c1\u94a5ca.key\u751f\u6210CA\u8ba4\u8bc1\u673a\u6784\u7684\u8bc1\u4e66ca.crt# \u5176\u5b9e\u5c31\u662f\u76f8\u5f53\u4e8e\u7528\u79c1\u94a5\u751f\u6210\u516c\u94a5\uff0c\u518d\u628a\u516c\u94a5\u5305\u88c5\u6210\u8bc1\u4e66<\/p>\n\n\n\n<p>openssl req -new -x509 -key ca.key -out ca.crt -days 3650<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u8bc1\u4e66ca.crt\u6709\u7684\u53c8\u79f0\u4e3a&#8221;\u6839\u8bc1\u4e66&#8221;,\u56e0\u4e3a\u53ef\u4ee5\u7528\u6765\u8ba4\u8bc1\u5176\u4ed6\u8bc1\u4e66<\/p>\n\n\n\n<p>\u5176\u6b21\uff0c\u624d\u662f\u751f\u6210\u7f51\u7ad9\u7684\u8bc1\u4e66<\/p>\n\n\n\n<p>\u7528\u4e0a\u9762\u90a3\u4e2a\u865a\u6784\u51fa\u6765\u7684CA\u673a\u6784\u6765\u8ba4\u8bc1\uff0c\u4e0d\u6536\u94b1\uff01<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>server \u7b7e\u540d<\/strong><\/h3>\n\n\n\n<p>\u751f\u6210\u5bc6\u94a5server.key\uff0c\u8f93\u5165\u79d8\u5bc6\uff1a123456<\/p>\n\n\n\n<p>openssl genrsa -des3 -out server.key 1024<\/p>\n\n\n\n<p>\u751f\u6210\u8bc1\u4e66\u7684\u8bf7\u6c42\u6587\u4ef6<\/p>\n\n\n\n<p>\u5982\u679c\u627e\u5916\u9762\u7684CA\u673a\u6784\u8ba4\u8bc1\uff0c\u4e5f\u662f\u53d1\u4e2a\u8bf7\u6c42\u6587\u4ef6\u7ed9\u4ed6\u4eec<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u79c1\u94a5\u5c31\u5305\u542b\u5728\u8bf7\u6c42\u6587\u4ef6\u4e2d\u4e86\uff0c\u8ba4\u8bc1\u673a\u6784\u8981\u7528\u5b83\u6765\u751f\u6210\u516c\u94a5\uff0c\u7136\u540e\u5305\u88c5\u6210\u4e00\u4e2a\u8bc1\u4e66<\/p>\n\n\n\n<p>openssl req -new -key server.key -out server.csr<\/p>\n\n\n\n<p>\u4f7f\u7528\u865a\u62df\u7684CA\u8ba4\u8bc1\u673a\u6784\u7684\u8bc1\u4e66ca.crt\uff0c\u6765\u5bf9\u8bc1\u4e66\u8bf7\u6c42\u6587\u4ef6server.csr\u8fdb\u884c\u5904\u7406\uff0c\u751f\u6210\u7b7e\u540d\u540e\u7684\u8bc1\u4e66server.crt<\/p>\n\n\n\n<p>\u6ce8\u610f\u8bbe\u7f6e\u5e8f\u5217\u53f7\u548c\u6709\u6548\u671f\uff08\u8bbe10\u5e74\uff09<\/p>\n\n\n\n<p>openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt -days 3650<\/p>\n\n\n\n<p>\u5c06server.key RSA private key \u8f6c\u6362\u6210pkcs8 \u7684private key<\/p>\n\n\n\n<p>openssl pkcs8 -topk8 -in server.key -out pkcs8_server.key -nocrypt<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Client\u7b7e\u540d<\/strong><\/h3>\n\n\n\n<p>\u751f\u6210\u5bc6\u94a5client.key\uff0c\u8f93\u5165\u79d8\u5bc6\uff1a123456<\/p>\n\n\n\n<p>openssl genrsa -des3 -out client.key 1024<\/p>\n\n\n\n<p>\u751f\u6210\u8bc1\u4e66\u7684\u8bf7\u6c42\u6587\u4ef6<\/p>\n\n\n\n<p>\u5982\u679c\u627e\u5916\u9762\u7684CA\u673a\u6784\u8ba4\u8bc1\uff0c\u4e5f\u662f\u53d1\u4e2a\u8bf7\u6c42\u6587\u4ef6\u7ed9\u4ed6\u4eec<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u79c1\u94a5\u5c31\u5305\u542b\u5728\u8bf7\u6c42\u6587\u4ef6\u4e2d\u4e86\uff0c\u8ba4\u8bc1\u673a\u6784\u8981\u7528\u5b83\u6765\u751f\u6210\u7f51\u7ad9\u7684\u516c\u94a5\uff0c\u7136\u540e\u5305\u88c5\u6210\u4e00\u4e2a\u8bc1\u4e66<\/p>\n\n\n\n<p>openssl req -new -key client.key -out client.csr<\/p>\n\n\n\n<p>\u4f7f\u7528\u865a\u62df\u7684CA\u8ba4\u8bc1\u673a\u6784\u7684\u8bc1\u4e66ca.crt\uff0c\u6765\u5bf9\u8bc1\u4e66\u8bf7\u6c42\u6587\u4ef6client.csr\u8fdb\u884c\u5904\u7406\uff0c\u751f\u6210\u7b7e\u540d\u540e\u7684\u8bc1\u4e66client.crt<\/p>\n\n\n\n<p>\u6ce8\u610f\u8bbe\u7f6e\u5e8f\u5217\u53f7\u548c\u6709\u6548\u671f\uff08\u8bbe10\u5e74\uff09<\/p>\n\n\n\n<p>openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out client.crt -days 3650<\/p>\n\n\n\n<p>\u5c06server.key RSA private key \u8f6c\u6362\u6210pkcs8 \u7684private key<\/p>\n\n\n\n<p>openssl pkcs8 -topk8 -in client.key -out pkcs8_client.key -nocrypt<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6700\u65e9\u53d1\u5e03\u4e8e\uff1a2022.09.30 09:28:38<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u4e8eNetty\u7684FileRegion\u6a21\u5f0f\u548cChunkedFile\u6a21\u5f0f\u5b9e\u73b0\u7684\u5927\u6587\u4ef6\u4f20\u8f93demo\uff0c\u5176\u4e2dChunkedFile\u4f7f\u7528\u4e86SSL\u3002<\/p>\n","protected":false},"author":1,"featured_media":238,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,7],"tags":[14],"class_list":["post-54","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-11","category-7","tag-14"],"jetpack_featured_media_url":"https:\/\/bbstone.cn\/wp-content\/uploads\/2023\/10\/368a32b3e1894e74b13d28026ecc37c7.png","_links":{"self":[{"href":"https:\/\/bbstone.cn\/index.php?rest_route=\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bbstone.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bbstone.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bbstone.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bbstone.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=54"}],"version-history":[{"count":5,"href":"https:\/\/bbstone.cn\/index.php?rest_route=\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":392,"href":"https:\/\/bbstone.cn\/index.php?rest_route=\/wp\/v2\/posts\/54\/revisions\/392"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bbstone.cn\/index.php?rest_route=\/wp\/v2\/media\/238"}],"wp:attachment":[{"href":"https:\/\/bbstone.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bbstone.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bbstone.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}