{"id":2028,"date":"2017-06-21T08:35:37","date_gmt":"2017-06-21T00:35:37","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=2028"},"modified":"2026-08-30T19:31:48","modified_gmt":"2026-08-30T11:31:48","slug":"java%e5%b8%b8%e7%94%a8%e5%8a%a0%e5%af%86%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=2028","title":{"rendered":"Java\u5e38\u7528\u52a0\u5bc6\u65b9\u5f0f"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\">\u52a0\u5bc6\u5c31\u662f\u628a\u660e\u6587\u53d8\u6210\u8def\u4e0a\u622a\u83b7\u4e5f\u770b\u4e0d\u61c2\u7684\u4e1c\u897f\uff0c\u9001\u5230\u63a5\u6536\u65b9\u540e\u518d\u7528\u914d\u5957\u7b97\u6cd5\u8fd8\u539f\u3002Java \u91cc\u5e38\u7528\u7684\u51e0\u7c7b\u662f <strong style=\"color: #4870ac;\">\u5bf9\u79f0\u52a0\u5bc6<\/strong>\u3001<strong style=\"color: #4870ac;\">\u975e\u5bf9\u79f0\u52a0\u5bc6<\/strong>\u3001<strong style=\"color: #4870ac;\">Base64 \u7f16\u7801<\/strong>\u3001<strong style=\"color: #4870ac;\">MD5 \u6458\u8981<\/strong>\u548c<strong style=\"color: #4870ac;\">\u6570\u5b57\u7b7e\u540d<\/strong>\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u6309\u8981\u4e0d\u8981\u5bc6\u94a5\u6765\u5206\uff1aBase64\u3001MD5 \u4e0d\u57fa\u4e8e key\uff1b\u5bf9\u79f0\u3001\u975e\u5bf9\u79f0\u3001\u6570\u5b57\u7b7e\u540d\u3001\u6570\u5b57\u8bc1\u4e66\u57fa\u4e8e key\u3002\u7f16\u7801\u548c\u89e3\u5bc6\u4e0d\u662f\u4e00\u56de\u4e8b\uff0c\u4e0b\u9762\u6309\u5bf9\u79f0 \u2192 \u975e\u5bf9\u79f0 \u2192 \u7f16\u7801\/\u6458\u8981 \u2192 \u7b7e\u540d\u628a\u4f8b\u5b50\u8dd1\u4e00\u904d\u3002<\/p>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u7c7b\u578b<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u5bc6\u94a5<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u5178\u578b\u7b97\u6cd5<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u5e72\u4ec0\u4e48<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7f16\u7801<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u65e0<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">Base64<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u53ef\u9006\u53d8\u6362\uff0c\u4e0d\u662f\u4fdd\u5bc6<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6458\u8981<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u65e0\uff08\u53ef\u52a0\u76d0\uff09<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">MD5 \/ SHA<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6821\u9a8c\u5b8c\u6574\u6027\uff0c\u539f\u5219\u4e0a\u4e0d\u53ef\u9006<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5bf9\u79f0\u52a0\u5bc6<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u540c\u4e00\u628a key<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">DES \/ 3DES \/ AES<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u52a0\u89e3\u5bc6\u90fd\u5feb\uff0c\u5bc6\u94a5\u8981\u4fdd\u7ba1\u597d<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u975e\u5bf9\u79f0\u52a0\u5bc6<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u516c\u94a5 + \u79c1\u94a5<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">RSA<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u516c\u94a5\u52a0\u5bc6\u3001\u79c1\u94a5\u89e3\u5bc6\uff08\u6216\u53cd\u8fc7\u6765\u7b7e\u540d\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6570\u5b57\u7b7e\u540d<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u79c1\u94a5\u7b7e\u540d \/ \u516c\u94a5\u9a8c\u7b7e<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">RSA + \u6458\u8981<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u9632\u62b5\u8d56\u3001\u9a8c\u6765\u6e90<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin: 1em 0px;\">\u52a0\u5bc6\u5f88\u5bb9\u6613\u7406\u89e3\uff0c\u5c31\u662f\u628a\u660e\u6587\u53d8\u6210\u4eba\u5bb6\u770b\u4e0d\u61c2\u7684\u4e1c\u897f\uff0c\u7136\u540e\u9001\u7ed9\u81ea\u5df1\u60f3\u8981\u7684\u9001\u5230\u7684\u5730\u65b9\uff0c\u63a5\u6536\u65b9\u7528\u914d\u5957\u7684\u89e3\u5bc6\u7b97\u6cd5\u53c8\u628a\u5bc6\u6587\u89e3\u5f00\u6210\u660e\u6587\uff0c\u8fd9\u6837\u5c31\u4e0d\u6015\u5728\u8def\u4e0a\u5982\u679c\u5bc6\u6587\u7ed9\u4eba\u5bb6\u622a\u83b7\u800c\u6cc4\u5bc6\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">\u76ee\u5f55\n\n1.\u5bf9\u79f0\u52a0\u5bc6\uff08Symmetric Cryptography\uff09\n\n2.\u975e\u5bf9\u79f0\u52a0\u5bc6\uff08Asymmetric Cryptography\uff09\n\n3.Base 64\u7f16\u7801\n\n4.MD5\u52a0\u5bc6\n\n5.\u6570\u5b57\u7b7e\u540d<\/code><\/pre>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">\u5e38\u7528\u52a0\u5bc6\u5e94\u7528\u6709:\n\nBase64\u7b97\u6cd5-\u7f16\u7801\u65b9\u5f0f\n\n\u6d88\u606f\u6458\u8981\u7b97\u6cd5-MD5--\u9a8c\u8bc1\u4fe1\u606f\u5b8c\u6574\u6027\n\n\u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5\n\n\u975e\u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5\n\n\u6570\u5b57\u7b7e\u540d\u7b97\u6cd5\n\n\u6570\u5b57\u8bc1\u4e66<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u52a0\u5bc6\u7b97\u6cd5\u6839\u636e\u662f\u5426\u9700\u8981key\u88ab\u5206\u4e3a\u4e24\u7c7b\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">\u4e0d\u57fa\u4e8ekey\u7684\u6709: Base64\u7b97\u6cd5,\u6d88\u606f\u6458\u8981\u7b97\u6cd5-MD5\n\n\u57fa\u4e8ekey\u7684\u6709: \u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5\u3001\u975e\u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5\u3001\u6570\u5b57\u7b7e\u540d\u7b97\u6cd5\u3001\u6570\u5b57\u8bc1\u4e66<\/code><\/pre>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001\u5bf9\u79f0\u52a0\u5bc6\uff08Symmetric Cryptography\uff09<\/h2>\n<p style=\"margin: 1em 0px;\">\u5bf9\u79f0\u52a0\u5bc6\u662f\u6700\u5feb\u901f\u3001\u6700\u7b80\u5355\u7684\u4e00\u79cd\u52a0\u5bc6\u65b9\u5f0f\uff0c\u52a0\u5bc6\uff08encryption\uff09\u4e0e\u89e3\u5bc6\uff08decryption\uff09\u7528\u7684\u662f\u540c\u6837\u7684\u5bc6\u94a5\uff08secret key\uff09\u3002\u5bf9\u79f0\u52a0\u5bc6\u6709\u5f88\u591a\u79cd\u7b97\u6cd5\uff0c\u7531\u4e8e\u5b83\u6548\u7387\u5f88\u9ad8\uff0c\u6240\u4ee5\u88ab\u5e7f\u6cdb\u4f7f\u7528\u5728\u5f88\u591a\u52a0\u5bc6\u534f\u8bae\u7684\u6838\u5fc3\u5f53\u4e2d\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u5bf9\u79f0\u52a0\u5bc6\u901a\u5e38\u4f7f\u7528\u7684\u662f\u76f8\u5bf9\u8f83\u5c0f\u7684\u5bc6\u94a5\uff0c\u4e00\u822c\u5c0f\u4e8e256 bit\u3002\u56e0\u4e3a\u5bc6\u94a5\u8d8a\u5927\uff0c\u52a0\u5bc6\u8d8a\u5f3a\uff0c\u4f46\u52a0\u5bc6\u4e0e\u89e3\u5bc6\u7684\u8fc7\u7a0b\u8d8a\u6162\u3002\u5982\u679c\u4f60\u53ea\u75281 bit\u6765\u505a\u8fd9\u4e2a\u5bc6\u94a5\uff0c\u90a3\u9ed1\u5ba2\u4eec\u53ef\u4ee5\u5148\u8bd5\u7740\u75280\u6765\u89e3\u5bc6\uff0c\u4e0d\u884c\u7684\u8bdd\u5c31\u518d\u75281\u89e3\uff1b\u4f46\u5982\u679c\u4f60\u7684\u5bc6\u94a5\u67091 MB\u5927\uff0c\u9ed1\u5ba2\u4eec\u53ef\u80fd\u6c38\u8fdc\u4e5f\u65e0\u6cd5\u7834\u89e3\uff0c\u4f46\u52a0\u5bc6\u548c\u89e3\u5bc6\u7684\u8fc7\u7a0b\u8981\u82b1\u8d39\u5f88\u957f\u7684\u65f6\u95f4\u3002\u5bc6\u94a5\u7684\u5927\u5c0f\u65e2\u8981\u7167\u987e\u5230\u5b89\u5168\u6027\uff0c\u4e5f\u8981\u7167\u987e\u5230\u6548\u7387\uff0c\u662f\u4e00\u4e2atrade-off\u3002<\/p>\n<p style=\"margin: 1em 0px;\">DES(Data Encryption Standard)\u548cTripleDES\u662f\u5bf9\u79f0\u52a0\u5bc6\u7684\u4e24\u79cd\u5b9e\u73b0\u3002<\/p>\n<p style=\"margin: 1em 0px;\">DES\u548cTripleDES\u57fa\u672c\u7b97\u6cd5\u4e00\u81f4\uff0c\u53ea\u662fTripleDES\u7b97\u6cd5\u63d0\u4f9b\u7684key\u4f4d\u6570\u66f4\u591a\uff0c\u52a0\u5bc6\u53ef\u9760\u6027\u66f4\u9ad8\u3002<\/p>\n<p style=\"margin: 1em 0px;\">DES\u4f7f\u7528\u7684\u5bc6\u94a5key\u4e3a8\u5b57\u8282\uff0c\u521d\u59cb\u5411\u91cfIV\u4e5f\u662f8\u5b57\u8282\u3002<\/p>\n<p style=\"margin: 1em 0px;\">TripleDES\u4f7f\u752824\u5b57\u8282\u7684key\uff0c\u521d\u59cb\u5411\u91cfIV\u4e5f\u662f8\u5b57\u8282\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u4e24\u79cd\u7b97\u6cd5\u90fd\u662f\u4ee58\u5b57\u8282\u4e3a\u4e00\u4e2a\u5757\u8fdb\u884c\u52a0\u5bc6\uff0c\u4e00\u4e2a\u6570\u636e\u5757\u4e00\u4e2a\u6570\u636e\u5757\u7684\u52a0\u5bc6\uff0c\u4e00\u4e2a8\u5b57\u8282\u7684\u660e\u6587\u52a0\u5bc6\u540e\u7684\u5bc6\u6587\u4e5f\u662f8\u5b57\u8282\u3002\u5982\u679c\u660e\u6587\u957f\u5ea6\u4e0d\u4e3a8\u5b57\u8282\u7684\u6574\u6570\u500d\uff0c\u6dfb\u52a0\u503c\u4e3a0\u7684\u5b57\u8282\u51d1\u6ee18\u5b57\u8282\u6574\u6570\u500d\u3002\u6240\u4ee5\u52a0\u5bc6\u540e\u7684\u5bc6\u6587\u957f\u5ea6\u4e00\u5b9a\u4e3a8\u5b57\u8282\u7684\u6574\u6570\u500d<\/p>\n<p style=\"margin: 1em 0px;\">\u4e0b\u9762\u4e3e\u4e2a\u4f8b\u5b50\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">package com.ittx.java1608.secure.utils;\n\nimport java.security.InvalidKeyException;\n\nimport java.security.Key;\n\nimport java.security.NoSuchAlgorithmException;\n\nimport java.security.SecureRandom;\n\nimport java.security.spec.InvalidKeySpecException;\n\nimport javax.crypto.Cipher;\n\nimport javax.crypto.SecretKey;\n\nimport javax.crypto.SecretKeyFactory;\n\nimport javax.crypto.spec.DESKeySpec;\n\nimport org.apache.commons.codec.binary.Base64;\n\npublic class DESDemo {\n\n\t\/\/ \u7b97\u6cd5\u540d\u79f0\n\n\tpublic static final String KEY_ALGORITHM = \"DES\";\n\n\t\/\/ \u7b97\u6cd5\u540d\u79f0\/\u52a0\u5bc6\u6a21\u5f0f\/\u586b\u5145\u65b9\u5f0f\n\n\t\/\/ DES\u5171\u6709\u56db\u79cd\u5de5\u4f5c\u6a21\u5f0f--&gt;&gt;ECB\uff1a\u7535\u5b50\u5bc6\u7801\u672c\u6a21\u5f0f\u3001CBC\uff1a\u52a0\u5bc6\u5206\u7ec4\u94fe\u63a5\u6a21\u5f0f\u3001CFB\uff1a\u52a0\u5bc6\u53cd\u9988\u6a21\u5f0f\u3001OFB\uff1a\u8f93\u51fa\u53cd\u9988\u6a21\u5f0f\n\n\tpublic static final String CIPHER_ALGORITHM = \"DES\/ECB\/NoPadding\";\n\n\t\/**\n\n\t *\n\n\t * \u751f\u6210\u5bc6\u94a5key\u5bf9\u8c61\n\n\t *\n\n\t * @param KeyStr\n\n\t *            \u5bc6\u94a5\u5b57\u7b26\u4e32\n\n\t * @return \u5bc6\u94a5\u5bf9\u8c61\n\n\t * @throws InvalidKeyException\n\n\t * @throws NoSuchAlgorithmException\n\n\t * @throws InvalidKeySpecException\n\n\t * @throws Exception\n\n\t *\/\n\n\tprivate static SecretKey keyGenerator(String keyStr) throws Exception {\n\n\t\tbyte input[] = HexString2Bytes(keyStr);\n\n\t\tDESKeySpec desKey = new DESKeySpec(input);\n\n\t\t\/\/ \u521b\u5efa\u4e00\u4e2a\u5bc6\u5319\u5de5\u5382\uff0c\u7136\u540e\u7528\u5b83\u628aDESKeySpec\u8f6c\u6362\u6210\n\n\t\tSecretKeyFactory keyFactory = SecretKeyFactory.getInstance(\"DES\");\n\n\t\tSecretKey securekey = keyFactory.generateSecret(desKey);\n\n\t\treturn securekey;\n\n\t}\n\n\tprivate static int parse(char c) {\n\n\t\tif (c &gt;= 'a')\n\n\t\t\treturn (c - 'a' + 10) &amp; 0x0f;\n\n\t\tif (c &gt;= 'A')\n\n\t\t\treturn (c - 'A' + 10) &amp; 0x0f;\n\n\t\treturn (c - '0') &amp; 0x0f;\n\n\t}\n\n\t\/\/ \u4ece\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u5230\u5b57\u8282\u6570\u7ec4\u8f6c\u6362\n\n\tpublic static byte[] HexString2Bytes(String hexstr) {\n\n\t\tbyte[] b = new byte[hexstr.length() \/ 2];\n\n\t\tint j = 0;\n\n\t\tfor (int i = 0; i &lt; b.length; i++) {\n\n\t\t\tchar c0 = hexstr.charAt(j++);\n\n\t\t\tchar c1 = hexstr.charAt(j++);\n\n\t\t\tb[i] = (byte) ((parse(c0) &lt;&lt; 4) | parse(c1));\n\n\t\t}\n\n\t\treturn b;\n\n\t}\n\n\t\/**\n\n\t * \u52a0\u5bc6\u6570\u636e\n\n\t *\n\n\t * @param data\n\n\t *            \u5f85\u52a0\u5bc6\u6570\u636e\n\n\t * @param key\n\n\t *            \u5bc6\u94a5\n\n\t * @return \u52a0\u5bc6\u540e\u7684\u6570\u636e\n\n\t *\/\n\n\tpublic static String encrypt(String data, String key) throws Exception {\n\n\t\tKey deskey = keyGenerator(key);\n\n\t\t\/\/ \u5b9e\u4f8b\u5316Cipher\u5bf9\u8c61\uff0c\u5b83\u7528\u4e8e\u5b8c\u6210\u5b9e\u9645\u7684\u52a0\u5bc6\u64cd\u4f5c\n\n\t\tCipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);\n\n\t\tSecureRandom random = new SecureRandom();\n\n\t\t\/\/ \u521d\u59cb\u5316Cipher\u5bf9\u8c61\uff0c\u8bbe\u7f6e\u4e3a\u52a0\u5bc6\u6a21\u5f0f\n\n\t\tcipher.init(Cipher.ENCRYPT_MODE, deskey, random);\n\n\t\tbyte[] results = cipher.doFinal(data.getBytes());\n\n\t\t\/\/ \u8be5\u90e8\u5206\u662f\u4e3a\u4e86\u4e0e\u52a0\u89e3\u5bc6\u5728\u7ebf\u6d4b\u8bd5\u7f51\u7ad9\uff08http:\/\/tripledes.online-domain-tools.com\/\uff09\u7684\u5341\u516d\u8fdb\u5236\u7ed3\u679c\u8fdb\u884c\u6838\u5bf9\n\n\t\tfor (int i = 0; i &lt; results.length; i++) {\n\n\t\t\tSystem.out.print(results[i] + \" \");\n\n\t\t}\n\n\t\tSystem.out.println();\n\n\t\t\/\/ \u6267\u884c\u52a0\u5bc6\u64cd\u4f5c\u3002\u52a0\u5bc6\u540e\u7684\u7ed3\u679c\u901a\u5e38\u90fd\u4f1a\u7528Base64\u7f16\u7801\u8fdb\u884c\u4f20\u8f93\n\n\t\treturn Base64.encodeBase64String(results);\n\n\t}\n\n\t\/**\n\n\t * \u89e3\u5bc6\u6570\u636e\n\n\t *\n\n\t * @param data\n\n\t *            \u5f85\u89e3\u5bc6\u6570\u636e\n\n\t * @param key\n\n\t *            \u5bc6\u94a5\n\n\t * @return \u89e3\u5bc6\u540e\u7684\u6570\u636e\n\n\t *\/\n\n\tpublic static String decrypt(String data, String key) throws Exception {\n\n\t\tKey deskey = keyGenerator(key);\n\n\t\tCipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);\n\n\t\t\/\/ \u521d\u59cb\u5316Cipher\u5bf9\u8c61\uff0c\u8bbe\u7f6e\u4e3a\u89e3\u5bc6\u6a21\u5f0f\n\n\t\tcipher.init(Cipher.DECRYPT_MODE, deskey);\n\n\t\t\/\/ \u6267\u884c\u89e3\u5bc6\u64cd\u4f5c\n\n\t\treturn new String(cipher.doFinal(Base64.decodeBase64(data)));\n\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\n\t\tString source = \"helloittx\";\n\n\t\tSystem.out.println(\"\u539f\u6587: \" + source);\n\n\t\tString key = \"A1B2C3D4E5F60708\";\n\n\t\tString encryptData = encrypt(source, key);\n\n\t\tSystem.out.println(\"\u52a0\u5bc6\u540e: \" + encryptData);\n\n\t\tString decryptData = decrypt(encryptData, key);\n\n\t\tSystem.out.println(\"\u89e3\u5bc6\u540e: \" + decryptData);\n\n\t}\n\n}<\/code><\/pre>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001\u975e\u5bf9\u79f0\u52a0\u5bc6\uff08Asymmetric Cryptography\uff09<\/h2>\n<p style=\"margin: 1em 0px;\">\u975e\u5bf9\u79f0\u52a0\u5bc6\u4e3a\u6570\u636e\u7684\u52a0\u5bc6\u4e0e\u89e3\u5bc6\u63d0\u4f9b\u4e86\u4e00\u4e2a\u975e\u5e38\u5b89\u5168\u7684\u65b9\u6cd5\uff0c\u5b83\u4f7f\u7528\u4e86\u4e00\u5bf9\u5bc6\u94a5\uff0c\u516c\u94a5\uff08public key\uff09\u548c\u79c1\u94a5\uff08private key\uff09\u3002\u79c1\u94a5\u53ea\u80fd\u7531\u4e00\u65b9\u5b89\u5168\u4fdd\u7ba1\uff0c\u4e0d\u80fd\u5916\u6cc4\uff0c\u800c\u516c\u94a5\u5219\u53ef\u4ee5\u53d1\u7ed9\u4efb\u4f55\u8bf7\u6c42\u5b83\u7684\u4eba\u3002\u975e\u5bf9\u79f0\u52a0\u5bc6\u4f7f\u7528\u8fd9\u5bf9\u5bc6\u94a5\u4e2d\u7684\u4e00\u4e2a\u8fdb\u884c\u52a0\u5bc6\uff0c\u800c\u89e3\u5bc6\u5219\u9700\u8981\u53e6\u4e00\u4e2a\u5bc6\u94a5\u3002\u6bd4\u5982\uff0c\u4f60\u5411\u94f6\u884c\u8bf7\u6c42\u516c\u94a5\uff0c\u94f6\u884c\u5c06\u516c\u94a5\u53d1\u7ed9\u4f60\uff0c\u4f60\u4f7f\u7528\u516c\u94a5\u5bf9\u6d88\u606f\u52a0\u5bc6\uff0c\u90a3\u4e48\u53ea\u6709\u79c1\u94a5\u7684\u6301\u6709\u4eba&#8211;\u94f6\u884c\u624d\u80fd\u5bf9\u4f60\u7684\u6d88\u606f\u89e3\u5bc6\u3002\u4e0e\u5bf9\u79f0\u52a0\u5bc6\u4e0d\u540c\u7684\u662f\uff0c\u94f6\u884c\u4e0d\u9700\u8981\u5c06\u79c1\u94a5\u901a\u8fc7\u7f51\u7edc\u53d1\u9001\u51fa\u53bb\uff0c\u56e0\u6b64\u5b89\u5168\u6027\u5927\u5927\u63d0\u9ad8\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u76ee\u524d\u6700\u5e38\u7528\u7684\u975e\u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5\u662fRSA\u7b97\u6cd5\uff0c\u662fRivest, Shamir, \u548cAdleman\u4e8e1978\u5e74\u53d1\u660e\uff0c\u4ed6\u4eec\u90a3\u65f6\u90fd\u662f\u5728MIT\u3002\u8bf7\u770b\u4e0b\u9762\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">package com.ittx.java1608.encrypt;\n\nimport java.io.FileInputStream;\n\nimport java.io.FileOutputStream;\n\nimport java.io.ObjectInputStream;\n\nimport java.io.ObjectOutputStream;\n\nimport java.math.BigInteger;\n\nimport java.security.Key;\n\nimport java.security.KeyFactory;\n\nimport java.security.KeyPair;\n\nimport java.security.KeyPairGenerator;\n\nimport java.security.SecureRandom;\n\nimport java.security.spec.RSAPrivateCrtKeySpec;\n\nimport java.security.spec.RSAPublicKeySpec;\n\nimport javax.crypto.Cipher;\n\nimport com.lxh.rsatest.HexUtil;\n\nimport Decoder.BASE64Decoder;\n\nimport Decoder.BASE64Encoder;\n\npublic class RSAEncrypt {\n\n\t\/** \u6307\u5b9a\u52a0\u5bc6\u7b97\u6cd5\u4e3aDESede *\/\n\n\tprivate static String ALGORITHM = \"RSA\";\n\n\t\/** \u6307\u5b9akey\u7684\u5927\u5c0f *\/\n\n\tprivate static int KEYSIZE = 1024;\n\n\t\/** \u6307\u5b9a\u516c\u94a5\u5b58\u653e\u6587\u4ef6 *\/\n\n\tprivate static String PUBLIC_KEY_FILE = \"public.keystore\";\n\n\t\/** \u6307\u5b9a\u79c1\u94a5\u5b58\u653e\u6587\u4ef6 *\/\n\n\tprivate static String PRIVATE_KEY_FILE = \"private.keystore\";\n\n\t\/**\n\n\t * \u751f\u6210\u5bc6\u94a5\u5bf9\n\n\t *\/\n\n\tprivate static void generateKeyPair() throws Exception {\n\n\t\t\/** RSA\u7b97\u6cd5\u8981\u6c42\u6709\u4e00\u4e2a\u53ef\u4fe1\u4efb\u7684\u968f\u673a\u6570\u6e90 *\/\n\n\t\tSecureRandom sr = new SecureRandom();\n\n\t\t\/** \u4e3aRSA\u7b97\u6cd5\u521b\u5efa\u4e00\u4e2aKeyPairGenerator\u5bf9\u8c61 *\/\n\n\t\tKeyPairGenerator kpg = KeyPairGenerator.getInstance(ALGORITHM);\n\n\t\t\/** \u5229\u7528\u4e0a\u9762\u7684\u968f\u673a\u6570\u636e\u6e90\u521d\u59cb\u5316\u8fd9\u4e2aKeyPairGenerator\u5bf9\u8c61 *\/\n\n\t\tkpg.initialize(KEYSIZE, sr);\n\n\t\t\/** \u751f\u6210\u5bc6\u5319\u5bf9 *\/\n\n\t\tKeyPair kp = kpg.generateKeyPair();\n\n\t\t\/** \u5f97\u5230\u516c\u94a5 *\/\n\n\t\tKey publicKey = kp.getPublic();\n\n\t\t\/** \u5f97\u5230\u79c1\u94a5 *\/\n\n\t\tKey privateKey = kp.getPrivate();\n\n\t\t\/** \u7528\u5bf9\u8c61\u6d41\u5c06\u751f\u6210\u7684\u5bc6\u94a5\u5199\u5165\u6587\u4ef6 *\/\n\n\t\tObjectOutputStream oos1 = new ObjectOutputStream(new FileOutputStream(PUBLIC_KEY_FILE));\n\n\t\tObjectOutputStream oos2 = new ObjectOutputStream(new FileOutputStream(PRIVATE_KEY_FILE));\n\n\t\toos1.writeObject(publicKey);\n\n\t\toos2.writeObject(privateKey);\n\n\t\t\/** \u6e05\u7a7a\u7f13\u5b58\uff0c\u5173\u95ed\u6587\u4ef6\u8f93\u51fa\u6d41 *\/\n\n\t\toos1.close();\n\n\t\toos2.close();\n\n\t}\n\n\t\/**\n\n\t * \u751f\u6210\u5bc6\u94a5\u5bf9\u5b57\u7b26\u4e32\n\n\t *\/\n\n\tprivate static void generateKeyPairString() throws Exception {\n\n\t\t\/** RSA\u7b97\u6cd5\u8981\u6c42\u6709\u4e00\u4e2a\u53ef\u4fe1\u4efb\u7684\u968f\u673a\u6570\u6e90 *\/\n\n\t\tSecureRandom sr = new SecureRandom();\n\n\t\t\/** \u4e3aRSA\u7b97\u6cd5\u521b\u5efa\u4e00\u4e2aKeyPairGenerator\u5bf9\u8c61 *\/\n\n\t\tKeyPairGenerator kpg = KeyPairGenerator.getInstance(ALGORITHM);\n\n\t\t\/** \u5229\u7528\u4e0a\u9762\u7684\u968f\u673a\u6570\u636e\u6e90\u521d\u59cb\u5316\u8fd9\u4e2aKeyPairGenerator\u5bf9\u8c61 *\/\n\n\t\tkpg.initialize(KEYSIZE, sr);\n\n\t\t\/** \u751f\u6210\u5bc6\u5319\u5bf9 *\/\n\n\t\tKeyPair kp = kpg.generateKeyPair();\n\n\t\t\/** \u5f97\u5230\u516c\u94a5 *\/\n\n\t\tKey publicKey = kp.getPublic();\n\n\t\t\/** \u5f97\u5230\u79c1\u94a5 *\/\n\n\t\tKey privateKey = kp.getPrivate();\n\n\t\t\/** \u7528\u5b57\u7b26\u4e32\u5c06\u751f\u6210\u7684\u5bc6\u94a5\u5199\u5165\u6587\u4ef6 *\/\n\n\t\tString algorithm = publicKey.getAlgorithm(); \/\/ \u83b7\u53d6\u7b97\u6cd5\n\n\t\tKeyFactory keyFact = KeyFactory.getInstance(algorithm);\n\n\t\tBigInteger prime = null;\n\n\t\tBigInteger exponent = null;\n\n\t\tRSAPublicKeySpec keySpec = (RSAPublicKeySpec) keyFact.getKeySpec(publicKey, RSAPublicKeySpec.class);\n\n\t\tprime = keySpec.getModulus();\n\n\t\texponent = keySpec.getPublicExponent();\n\n\t\tSystem.out.println(\"\u516c\u94a5\u6a21\u91cf\uff1a\" + HexUtil.bytes2Hex(prime.toByteArray()));\n\n\t\tSystem.out.println(\"\u516c\u94a5\u6307\u6570:\" + HexUtil.bytes2Hex(exponent.toByteArray()));\n\n\t\tSystem.out.println(privateKey.getAlgorithm());\n\n\t\tRSAPrivateCrtKeySpec privateKeySpec = (RSAPrivateCrtKeySpec) keyFact.getKeySpec(privateKey,\n\n\t\t\t\tRSAPrivateCrtKeySpec.class);\n\n\t\tBigInteger privateModulus = privateKeySpec.getModulus();\n\n\t\tBigInteger privateExponent = privateKeySpec.getPrivateExponent();\n\n\t\tSystem.out.println(\"\u79c1\u94a5\u6a21\u91cf\uff1a\" + HexUtil.bytes2Hex(privateModulus.toByteArray()));\n\n\t\tSystem.out.println(\"\u79c1\u94a5\u6307\u6570:\" + HexUtil.bytes2Hex(privateExponent.toByteArray()));\n\n\t}\n\n\t\/**\n\n\t * \u52a0\u5bc6\u65b9\u6cd5 source\uff1a \u6e90\u6570\u636e\n\n\t *\/\n\n\tpublic static String encrypt(String source) throws Exception {\n\n\t\tgenerateKeyPair();\n\n\t\t\/** \u5c06\u6587\u4ef6\u4e2d\u7684\u516c\u94a5\u5bf9\u8c61\u8bfb\u51fa *\/\n\n\t\tObjectInputStream ois = new ObjectInputStream(new FileInputStream(PUBLIC_KEY_FILE));\n\n\t\tKey key = (Key) ois.readObject();\n\n\t\tois.close();\n\n\t\tString algorithm = key.getAlgorithm(); \/\/ \u83b7\u53d6\u7b97\u6cd5\n\n\t\tKeyFactory keyFact = KeyFactory.getInstance(algorithm);\n\n\t\tBigInteger prime = null;\n\n\t\tBigInteger exponent = null;\n\n\t\tif (\"RSA\".equals(algorithm)) { \/\/ \u5982\u679c\u662fRSA\u52a0\u5bc6\n\n\t\t\tRSAPublicKeySpec keySpec = (RSAPublicKeySpec) keyFact.getKeySpec(key, RSAPublicKeySpec.class);\n\n\t\t\tprime = keySpec.getModulus();\n\n\t\t\texponent = keySpec.getPublicExponent();\n\n\/\/\t\t\tSystem.out.println(\"\u516c\u94a5\u6a21\u91cf\uff1a\" + HexUtil.bytes2Hex(prime.toByteArray()));\n\n\/\/\t\t\tSystem.out.println(\"\u516c\u94a5\u6307\u6570:\" + HexUtil.bytes2Hex(exponent.toByteArray()));\n\n\t\t}\n\n\t\t\/** \u5f97\u5230Cipher\u5bf9\u8c61\u6765\u5b9e\u73b0\u5bf9\u6e90\u6570\u636e\u7684RSA\u52a0\u5bc6 *\/\n\n\t\tCipher cipher = Cipher.getInstance(ALGORITHM);\n\n\t\tcipher.init(Cipher.ENCRYPT_MODE, key);\n\n\t\tbyte[] b = source.getBytes();\n\n\t\t\/** \u6267\u884c\u52a0\u5bc6\u64cd\u4f5c *\/\n\n\t\tbyte[] b1 = cipher.doFinal(b);\n\n\t\tBASE64Encoder encoder = new BASE64Encoder();\n\n\t\treturn encoder.encode(b1);\n\n\t}\n\n\t\/**\n\n\t * \u89e3\u5bc6\u7b97\u6cd5 cryptograph:\u5bc6\u6587\n\n\t *\/\n\n\tpublic static String decrypt(String cryptograph) throws Exception {\n\n\t\t\/** \u5c06\u6587\u4ef6\u4e2d\u7684\u79c1\u94a5\u5bf9\u8c61\u8bfb\u51fa *\/\n\n\t\tObjectInputStream ois = new ObjectInputStream(new FileInputStream(PRIVATE_KEY_FILE));\n\n\t\tKey key = (Key) ois.readObject();\n\n\t\tString algorithm = key.getAlgorithm(); \/\/ \u83b7\u53d6\u7b97\u6cd5\n\n\t\tKeyFactory keyFact = KeyFactory.getInstance(algorithm);\n\n\t\tRSAPrivateCrtKeySpec privateKeySpec = (RSAPrivateCrtKeySpec) keyFact.getKeySpec(key,\n\n\t\t\t\tRSAPrivateCrtKeySpec.class);\n\n\t\tBigInteger privateModulus = privateKeySpec.getModulus();\n\n\t\tBigInteger privateExponent = privateKeySpec.getPrivateExponent();\n\n\/\/\t\tSystem.out.println(\"\u79c1\u94a5\u6a21\u91cf\uff1a\" + HexUtil.bytes2Hex(privateModulus.toByteArray()));\n\n\/\/\t\tSystem.out.println(\"\u79c1\u94a5\u6307\u6570:\" + HexUtil.bytes2Hex(privateExponent.toByteArray()));\n\n\t\t\/** \u5f97\u5230Cipher\u5bf9\u8c61\u5bf9\u5df2\u7528\u516c\u94a5\u52a0\u5bc6\u7684\u6570\u636e\u8fdb\u884cRSA\u89e3\u5bc6 *\/\n\n\t\tCipher cipher = Cipher.getInstance(ALGORITHM);\n\n\t\tcipher.init(Cipher.DECRYPT_MODE, key);\n\n\t\tBASE64Decoder decoder = new BASE64Decoder();\n\n\t\tbyte[] b1 = decoder.decodeBuffer(cryptograph);\n\n\t\t\/** \u6267\u884c\u89e3\u5bc6\u64cd\u4f5c *\/\n\n\t\tbyte[] b = cipher.doFinal(b1);\n\n\t\treturn new String(b);\n\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\n\t\tgenerateKeyPair(); \/\/\u751f\u6210\u6587\u4ef6\u5f62\u5f0f\u516c\u94a5\u548c\u79c1\u94a5\n\n\t\t\/\/generateKeyPairString();\/\/\u751f\u6210\u5b57\u7b26\u4e32\u5f62\u5f0f\u516c\u94a5\u548c\u79c1\u94a5\n\n\t\tString source = \"\u975e\u5bf9\u79f0\u52a0\u5bc6RSA\";\/\/ \u8981\u52a0\u5bc6\u7684\u5b57\u7b26\u4e32\n\n\t\tString cryptograph = encrypt(source);\/\/ \u751f\u6210\u7684\u5bc6\u6587\n\n\t\tString hexCrypt = HexUtil.bytes2Hex(cryptograph.getBytes(), false);\n\n\t\tSystem.out.println(\"\u751f\u6210\u7684\u5bc6\u6587---&gt;\" + hexCrypt);\n\n\t\tString target = decrypt(HexUtil.hex2String(hexCrypt));\/\/ \u89e3\u5bc6\u5bc6\u6587\n\n\t\tSystem.out.println(\"\u89e3\u5bc6\u5bc6\u6587---&gt;\" + target);\n\n\t}\n\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">&nbsp;<\/p>\n<p style=\"margin: 1em 0px;\">\u867d\u7136\u975e\u5bf9\u79f0\u52a0\u5bc6\u5f88\u5b89\u5168\uff0c\u4f46\u662f\u548c\u5bf9\u79f0\u52a0\u5bc6\u6bd4\u8d77\u6765\uff0c\u5b83\u975e\u5e38\u7684\u6162\uff0c\u6240\u4ee5\u6211\u4eec\u8fd8\u662f\u8981\u7528\u5bf9\u79f0\u52a0\u5bc6\u6765\u4f20\u9001\u6d88\u606f\uff0c\u4f46\u5bf9\u79f0\u52a0\u5bc6\u6240\u4f7f\u7528\u7684\u5bc6\u94a5\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u975e\u5bf9\u79f0\u52a0\u5bc6\u7684\u65b9\u5f0f\u53d1\u9001\u51fa\u53bb\u3002\u4e3a\u4e86\u89e3\u91ca\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u8bf7\u770b\u4e0b\u9762\u7684\u4f8b\u5b50\uff1a<\/p>\n<p style=\"margin: 1em 0px;\">\uff081\uff09 Alice\u9700\u8981\u5728\u94f6\u884c\u7684\u7f51\u7ad9\u505a\u4e00\u7b14\u4ea4\u6613\uff0c\u5979\u7684\u6d4f\u89c8\u5668\u9996\u5148\u751f\u6210\u4e86\u4e00\u4e2a\u968f\u673a\u6570\u4f5c\u4e3a\u5bf9\u79f0\u5bc6\u94a5\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\uff082\uff09 Alice\u7684\u6d4f\u89c8\u5668\u5411\u94f6\u884c\u7684\u7f51\u7ad9\u8bf7\u6c42\u516c\u94a5\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\uff083\uff09 \u94f6\u884c\u5c06\u516c\u94a5\u53d1\u9001\u7ed9Alice\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\uff084\uff09 Alice\u7684\u6d4f\u89c8\u5668\u4f7f\u7528\u94f6\u884c\u7684\u516c\u94a5\u5c06\u81ea\u5df1\u7684\u5bf9\u79f0\u5bc6\u94a5\u52a0\u5bc6\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\uff085\uff09 Alice\u7684\u6d4f\u89c8\u5668\u5c06\u52a0\u5bc6\u540e\u7684\u5bf9\u79f0\u5bc6\u94a5\u53d1\u9001\u7ed9\u94f6\u884c\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\uff086\uff09 \u94f6\u884c\u4f7f\u7528\u79c1\u94a5\u89e3\u5bc6\u5f97\u5230Alice\u6d4f\u89c8\u5668\u7684\u5bf9\u79f0\u5bc6\u94a5\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\uff087\uff09 Alice\u4e0e\u94f6\u884c\u53ef\u4ee5\u4f7f\u7528\u5bf9\u79f0\u5bc6\u94a5\u6765\u5bf9\u6c9f\u901a\u7684\u5185\u5bb9\u8fdb\u884c\u52a0\u5bc6\u4e0e\u89e3\u5bc6\u4e86\u3002<\/p>\n<p style=\"margin: 1em 0px;\">&nbsp;<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"http:\/\/images.cnitblog.com\/blog\/442200\/201410\/121924251089094.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" title=\"image_thumb3\" src=\"http:\/\/images.cnitblog.com\/blog\/442200\/201410\/121924258581724.png\" alt=\"image_thumb3\" width=\"646\" height=\"333\" border=\"0\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e09\u3001\u603b\u7ed3<\/h2>\n<p style=\"margin: 1em 0px;\">\uff081\uff09 \u5bf9\u79f0\u52a0\u5bc6\u52a0\u5bc6\u4e0e\u89e3\u5bc6\u4f7f\u7528\u7684\u662f\u540c\u6837\u7684\u5bc6\u94a5\uff0c\u6240\u4ee5\u901f\u5ea6\u5feb\uff0c\u4f46\u7531\u4e8e\u9700\u8981\u5c06\u5bc6\u94a5\u5728\u7f51\u7edc\u4f20\u8f93\uff0c\u6240\u4ee5\u5b89\u5168\u6027\u4e0d\u9ad8\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\uff082\uff09 \u975e\u5bf9\u79f0\u52a0\u5bc6\u4f7f\u7528\u4e86\u4e00\u5bf9\u5bc6\u94a5\uff0c\u516c\u94a5\u4e0e\u79c1\u94a5\uff0c\u6240\u4ee5\u5b89\u5168\u6027\u9ad8\uff0c\u4f46\u52a0\u5bc6\u4e0e\u89e3\u5bc6\u901f\u5ea6\u6162\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\uff083\uff09 \u89e3\u51b3\u7684\u529e\u6cd5\u662f\u5c06\u5bf9\u79f0\u52a0\u5bc6\u7684\u5bc6\u94a5\u4f7f\u7528\u975e\u5bf9\u79f0\u52a0\u5bc6\u7684\u516c\u94a5\u8fdb\u884c\u52a0\u5bc6\uff0c\u7136\u540e\u53d1\u9001\u51fa\u53bb\uff0c\u63a5\u6536\u65b9\u4f7f\u7528\u79c1\u94a5\u8fdb\u884c\u89e3\u5bc6\u5f97\u5230\u5bf9\u79f0\u52a0\u5bc6\u7684\u5bc6\u94a5\uff0c\u7136\u540e\u53cc\u65b9\u53ef\u4ee5\u4f7f\u7528\u5bf9\u79f0\u52a0\u5bc6\u6765\u8fdb\u884c\u6c9f\u901a\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u53c2\u8003\u5730\u5740\uff1a<a href=\"http:\/\/www.cnblogs.com\/jfzhu\/p\/4020928.html\">http:\/\/www.cnblogs.com\/jfzhu\/p\/4020928.html<\/a><\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u56db\u3001Encoding VS. Encryption<\/h2>\n<p style=\"margin: 1em 0px;\">\u5f88\u591a\u4eba\u90fd\u4ee5\u4e3a\u7f16\u7801\uff08Encoding\uff09\u548c\u52a0\u5bc6\uff08Encryption\uff09\u662f\u540c\u4e00\u4e2a\u610f\u601d\u3002\u7f16\u7801\u548c\u52a0\u5bc6\u90fd\u662f\u5bf9\u683c\u5f0f\u7684\u4e00\u79cd\u8f6c\u6362\uff0c\u4f46\u662f\u5b83\u4eec\u662f\u6709\u533a\u522b\u7684\u3002\u7f16\u7801\u662f\u516c\u5f00\u7684\uff0c\u6bd4\u5982\u4e0b\u9762\u8981\u4ecb\u7ecd\u7684Base 64\u7f16\u7801\uff0c\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u89e3\u7801\uff1b\u800c\u52a0\u5bc6\u5219\u76f8\u53cd\uff0c\u4f60\u53ea\u5e0c\u671b\u81ea\u5df1\u6216\u8005\u7279\u5b9a\u7684\u4eba\u624d\u53ef\u4ee5\u5bf9\u5185\u5bb9\u8fdb\u884c\u89e3\u5bc6\u3002<\/p>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">1. Base 64\u7f16\u7801<\/h3>\n<p style=\"margin: 1em 0px;\">Base 64 Encoding\u6709\u4ec0\u4e48\u7528\uff1f\u4e3e\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u4f60\u4f7f\u7528SMTP\u534f\u8bae \uff08Simple Mail Transfer Protocol \u7b80\u5355\u90ae\u4ef6\u4f20\u8f93\u534f\u8bae\uff09\u6765\u53d1\u9001\u90ae\u4ef6\u3002\u56e0\u4e3a\u8fd9\u4e2a\u534f\u8bae\u662f\u57fa\u4e8e\u6587\u672c\u7684\u534f\u8bae\uff0c\u6240\u4ee5\u5982\u679c\u90ae\u4ef6\u4e2d\u5305\u542b\u4e00\u5e45\u56fe\u7247\uff0c\u6211\u4eec\u77e5\u9053\u56fe\u7247\u7684\u5b58\u50a8\u683c\u5f0f\u662f\u4e8c\u8fdb\u5236\u6570\u636e\uff08binary data\uff09\uff0c\u800c\u975e\u6587\u672c\u683c\u5f0f\uff0c\u6211\u4eec\u5fc5\u987b\u5c06\u4e8c\u8fdb\u5236\u7684\u6570\u636e\u7f16\u7801\u6210\u6587\u672c\u683c\u5f0f\uff0c\u8fd9\u65f6\u5019Base 64 Encoding\u5c31\u6d3e\u4e0a\u7528\u573a\u4e86\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">public void testJDKBase64(){\n\n\tString encoderStr = java.util.Base64.getEncoder().encodeToString(s.getBytes());\n\n\tSystem.out.println(\"encode :\"+encoderStr);\n\n\tString decodeStr = new String(java.util.Base64.getDecoder().decode(encoderStr));\n\n\tSystem.out.println(\"decodeStr :\"+decodeStr);\n\n}\n\npublic void testCodecBase64(){\n\n\tString encoderStr = org.apache.commons.codec.binary.Base64.encodeBase64String(s.getBytes());\n\n\tSystem.out.println(\"encode :\"+encoderStr);\n\n\tString decodeStr = new String(org.apache.commons.codec.binary.Base64.decodeBase64(encoderStr));\n\n\tSystem.out.println(\"decodeStr :\"+decodeStr);\n\n}<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">2. MD5\u52a0\u5bc6<\/h3>\n<h4 style=\"padding: 0px; color: #4870ac; margin: 1em 0px 0.6em; font-size: 1.1em;\">2.1 \u6982\u8ff0<\/h4>\n<p style=\"margin: 1em 0px;\">Message Digest Algorithm MD5\uff08\u4e2d\u6587\u540d\u4e3a\u6d88\u606f\u6458\u8981\u7b97\u6cd5\u7b2c\u4e94\u7248\uff09\u4e3a\u8ba1\u7b97\u673a\u5b89\u5168\u9886\u57df\u5e7f\u6cdb\u4f7f\u7528\u7684\u4e00\u79cd\u6563\u5217\u51fd\u6570\uff0c\u7528\u4ee5\u63d0\u4f9b\u6d88\u606f\u7684\u5b8c\u6574\u6027\u4fdd\u62a4\u3002\u8be5\u7b97\u6cd5\u7684\u6587\u4ef6\u53f7\u4e3aRFC 1321\uff08R.Rivest,MIT Laboratory for Computer Science and RSA Data Security Inc. April 1992\uff09.<\/p>\n<p style=\"margin: 1em 0px;\">MD5\u7684\u5168\u79f0\u662fMessage-Digest Algorithm 5\uff08\u4fe1\u606f-\u6458\u8981\u7b97\u6cd5\uff09\uff0c\u572890\u5e74\u4ee3\u521d\u7531MIT Laboratory for Computer Science\u548cRSA Data Security Inc\u7684Ronald L. Rivest\u5f00\u53d1\u51fa\u6765\uff0c\u7ecfMD2\u3001MD3\u548cMD4\u53d1\u5c55\u800c\u6765\u3002<\/p>\n<p style=\"margin: 1em 0px;\">MD5\u7528\u4e8e\u786e\u4fdd\u4fe1\u606f\u4f20\u8f93\u5b8c\u6574\u4e00\u81f4\u3002\u662f\u8ba1\u7b97\u673a\u5e7f\u6cdb\u4f7f\u7528\u7684\u6742\u51d1\u7b97\u6cd5\u4e4b\u4e00\uff08\u53c8\u8bd1\u6458\u8981\u7b97\u6cd5\u3001\u54c8\u5e0c\u7b97\u6cd5\uff09\uff0c\u4e3b\u6d41\u7f16\u7a0b\u8bed\u8a00\u666e\u904d\u5df2\u6709MD5\u5b9e\u73b0\u3002\u5c06\u6570\u636e\uff08\u5982\u6c49\u5b57\uff09\u8fd0\u7b97\u4e3a\u53e6\u4e00\u56fa\u5b9a\u957f\u5ea6\u503c\uff0c\u662f\u6742\u51d1\u7b97\u6cd5\u7684\u57fa\u7840\u539f\u7406\uff0cMD5\u7684\u524d\u8eab\u6709MD2\u3001MD3\u548cMD4\u3002<\/p>\n<p style=\"margin: 1em 0px;\">MD5\u7684\u4f5c\u7528\u662f\u8ba9\u5927\u5bb9\u91cf\u4fe1\u606f\u5728\u7528\u6570\u5b57\u7b7e\u540d\u8f6f\u4ef6\u7b7e\u7f72\u79c1\u4eba\u5bc6\u94a5\u524d\u88ab&#8221;\u538b\u7f29&#8221;\u6210\u4e00\u79cd\u4fdd\u5bc6\u7684\u683c\u5f0f\uff08\u5c31\u662f\u628a\u4e00\u4e2a\u4efb\u610f\u957f\u5ea6\u7684\u5b57\u8282\u4e32\u53d8\u6362\u6210\u4e00\u5b9a\u957f\u7684\u5341\u516d\u8fdb\u5236\u6570\u5b57\u4e32\uff09\u3002<\/p>\n<h4 style=\"padding: 0px; color: #4870ac; margin: 1em 0px 0.6em; font-size: 1.1em;\">2.2 Java\u5b9e\u73b0<\/h4>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">package com.ittx.java1608.secure.utils;\n\nimport java.security.MessageDigest;\n\nimport java.security.NoSuchAlgorithmException;\n\n\/**\n\n * Java\u6d88\u606f\u6458\u8981\u7b97\u6cd5 MD5 \u5de5\u5177\u7c7b,\u5176\u5b9e\u5176\u4ed6\u6458\u8981\u7b97\u6cd5\u7684\u5b9e\u73b0\u4e5f\u7c7b\u4f3c\n\n *\/\n\npublic class MD5Util {\n\n\t\/**\n\n\t * \u5bf9\u6587\u672c\u6267\u884c md5 \u6458\u8981\u52a0\u5bc6, \u6b64\u7b97\u6cd5\u4e0e mysql,JavaScript\u751f\u6210\u7684md5\u6458\u8981\u8fdb\u884c\u8fc7\u4e00\u81f4\u6027\u5bf9\u6bd4.\n\n\t * @param plainText\n\n\t * @return \u8fd4\u56de\u503c\u4e2d\u7684\u5b57\u6bcd\u4e3a\u5c0f\u5199\n\n\t *\/\n\n\tpublic static String md5(String plainText) {\n\n\t\tif (null == plainText) {\n\n\t\t\tplainText = \"\";\n\n\t\t}\n\n\t\tString MD5Str = \"\";\n\n\t\ttry {\n\n\t\t\t\/\/ JDK 6 \u652f\u6301\u4ee5\u4e0b6\u79cd\u6d88\u606f\u6458\u8981\u7b97\u6cd5\uff0c\u4e0d\u533a\u5206\u5927\u5c0f\u5199\n\n\t\t\t\/\/ md5,sha(sha-1),md2,sha-256,sha-384,sha-512\n\n\t\t\tMessageDigest md = MessageDigest.getInstance(\"MD5\");\n\n\t\t\tmd.update(plainText.getBytes());\n\n\t\t\tbyte b[] = md.digest();\n\n\t\t\tint i;\n\n\t\t\tStringBuilder builder = new StringBuilder(32);\n\n\t\t\tfor (int offset = 0; offset &lt; b.length; offset++) {\n\n\t\t\t\ti = b[offset];\n\n\t\t\t\tif (i &lt; 0)\n\n\t\t\t\t\ti += 256;\n\n\t\t\t\tif (i &lt; 16)\n\n\t\t\t\t\tbuilder.append(\"0\");\n\n\t\t\t\tbuilder.append(Integer.toHexString(i));\n\n\t\t\t}\n\n\t\t\tMD5Str = builder.toString();\n\n\t\t\t\/\/ LogUtil.println(\"result: \" + buf.toString());\/\/ 32\u4f4d\u7684\u52a0\u5bc6\n\n\t\t} catch (NoSuchAlgorithmException e) {\n\n\t\t\te.printStackTrace();\n\n\t\t}\n\n\t\treturn MD5Str;\n\n\t}\n\n\t\/\/ \u4e00\u4e2a\u7b80\u7248\u6d4b\u8bd5\n\n\tpublic static void main(String[] args) {\n\n\t\tString m1 = md5(\"1\");\n\n\t\tString m2 = md5(m1);\n\n\t\t\/* \u8f93\u51fa\u4e3a\n\n\t\t * m1=c4ca4238a0b923820dcc509a6f75849b\n\n\t\t * m2=28c8edde3d61a0411511d3b1866f0636\n\n\t\t *\/\n\n\t\tSystem.out.println(\"m1=\"+m1);\n\n\t\tSystem.out.println(\"m2=\"+m2);\n\n\t}\n\n}<\/code><\/pre>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e94\u3001\u6570\u5b57\u7b7e\u540d\u7b97\u6cd5<\/h2>\n<p style=\"margin: 1em 0px;\">\u7b7e\u540d\uff1a\u5c31\u6709\u5b89\u5168\u6027\uff0c\u6297\u5426\u8ba4\u6027<\/p>\n<p style=\"margin: 1em 0px;\">\u6570\u5b57\u7b7e\u540d\uff1a\u5e26\u6709\u5bc6\u94a5\uff08\u516c\u94a5\uff0c\u79c1\u94a5\uff09\u7684\u6d88\u606f\u6458\u8981<a class=\"replace_word\" title=\"\u7b97\u6cd5\u4e0e\u6570\u636e\u7ed3\u6784\u77e5\u8bc6\u5e93\" href=\"http:\/\/lib.csdn.net\/base\/datastructure\" target=\"_blank\" rel=\"noopener\">\u7b97\u6cd5<\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u4f5c\u7528\uff1a<\/p>\n<p style=\"margin: 1em 0px;\">1. \u9a8c\u8bc1\u6570\u636e\u7684\u5b8c\u6574\u6027<\/p>\n<p style=\"margin: 1em 0px;\">2. \u8ba4\u8bc1\u6570\u636e\u6765\u6e90<\/p>\n<p style=\"margin: 1em 0px;\">3. \u6297\u5426\u8ba4<\/p>\n<p style=\"margin: 1em 0px;\">\u6570\u5b57\u7b7e\u540d\u9075\u5faa\uff1a\u79c1\u94a5\u7b7e\u540d\uff0c\u516c\u94a5\u9a8c\u8bc1<\/p>\n<p style=\"margin: 1em 0px;\">\u5e38\u7528\u7684\u6570\u5b57\u7b7e\u540d\u7b97\u6cd5\uff1aRSA\uff0cDSA\uff0cECDSA<\/p>\n<p style=\"margin: 1em 0px;\">RSA<strong style=\"color: #4870ac;\">\u4ecb\u7ecd\uff1a<\/strong><\/p>\n<p style=\"margin: 1em 0px;\">\u662f\u7ecf\u5178\u7b97\u6cd5\uff0c\u662f\u76ee\u524d\u4e3a\u6b62\u4f7f\u7528\u6700\u5e7f\u6cdb\u7684\u6570\u5b57\u7b7e\u540d\u7b97\u6cd5\u3002<\/p>\n<p style=\"margin: 1em 0px;\">RSA\u6570\u5b57\u7b7e\u540d\u7b97\u6cd5\u7684\u5bc6\u94a5\u5b9e\u73b0\u4e0eRSA\u7684\u52a0\u5bc6\u7b97\u6cd5\u662f\u4e00\u6837\u7684\uff0c\u7b97\u6cd5\u7684\u540d\u79f0\u90fd\u53ebRSA\u3002\u5bc6\u94a5\u7684\u4ea7\u751f\u548c\u8f6c\u6362\u90fd\u662f\u4e00\u6837\u7684\u3002<\/p>\n<p style=\"margin: 1em 0px;\">RSA\u6570\u5b57\u7b7e\u540d\u7b97\u6cd5\u4e3b\u8981\u5305\u62ecMD\u548cSHA\u4e24\u7c7b\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">package com.ittx.security.signature;\n\nimport java.security.KeyFactory;\n\nimport java.security.KeyPair;\n\nimport java.security.KeyPairGenerator;\n\nimport java.security.PrivateKey;\n\nimport java.security.PublicKey;\n\nimport java.security.Signature;\n\nimport java.security.interfaces.RSAPrivateKey;\n\nimport java.security.interfaces.RSAPublicKey;\n\nimport java.security.spec.PKCS8EncodedKeySpec;\n\nimport java.security.spec.X509EncodedKeySpec;\n\nimport org.apache.commons.codec.binary.Hex;\n\npublic class RSATest {\n\n    public static final String src = \"hello world\";\n\n    public static void main(String[] args) {\n\n        jdkRSA();\n\n    }\n\n    \/**\n\n     * \u8bf4\u660e\uff1a \u7528java\u7684jdk\u91cc\u9762\u76f8\u5173\u65b9\u6cd5\u5b9e\u73b0rsa\u7684\u7b7e\u540d\u53ca\u7b7e\u540d\u9a8c\u8bc1\n\n     *\/\n\n    public static void jdkRSA() {\n\n        try {\n\n            \/\/ 1.\u521d\u59cb\u5316\u5bc6\u94a5\n\n            KeyPairGenerator keyPairGenerator = KeyPairGenerator\n\n                    .getInstance(\"RSA\");\n\n            \/\/\u8bbe\u7f6eKEY\u7684\u957f\u5ea6\n\n            keyPairGenerator.initialize(512);\n\n            KeyPair keyPair = keyPairGenerator.generateKeyPair();\n\n            \/\/\u5f97\u5230\u516c\u94a5\n\n            RSAPublicKey rsaPublicKey = (RSAPublicKey) keyPair.getPublic();\n\n            \/\/\u5f97\u5230\u79c1\u94a5\n\n            RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) keyPair.getPrivate();\n\n            \/\/ 2.\u8fdb\u884c\u7b7e\u540d\n\n            \/\/\u7528\u79c1\u94a5\u8fdb\u884c\u7b7e\u540d\n\n            PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(\n\n                    rsaPrivateKey.getEncoded());\n\n            KeyFactory keyFactory = KeyFactory.getInstance(\"RSA\");\n\n            \/\/\u6784\u9020\u4e00\u4e2aprivateKey\n\n            PrivateKey privateKey = keyFactory\n\n                    .generatePrivate(pkcs8EncodedKeySpec);\n\n            \/\/\u58f0\u660e\u7b7e\u540d\u7684\u5bf9\u8c61\n\n            Signature signature = Signature.getInstance(\"MD5withRSA\");\n\n            signature.initSign(privateKey);\n\n            signature.update(src.getBytes());\n\n            \/\/\u8fdb\u884c\u7b7e\u540d\n\n            byte[] result = signature.sign();\n\n            System.out.println(\"jdk rsa sign:\" + Hex.encodeHexString(result));\n\n            \/\/ 3.\u9a8c\u8bc1\u7b7e\u540d\n\n            \/\/\u7528\u516c\u94a5\u8fdb\u884c\u9a8c\u8bc1\u7b7e\u540d\n\n            X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(\n\n                    rsaPublicKey.getEncoded());\n\n            keyFactory = KeyFactory.getInstance(\"RSA\");\n\n            \/\/\u6784\u9020\u4e00\u4e2apublicKey\n\n            PublicKey publicKey = keyFactory.generatePublic(x509EncodedKeySpec);\n\n            \/\/\u58f0\u660e\u7b7e\u540d\u5bf9\u8c61\n\n            signature = Signature.getInstance(\"MD5withRSA\");\n\n            signature.initVerify(publicKey);\n\n            signature.update(src.getBytes());\n\n            \/\/\u9a8c\u8bc1\u7b7e\u540d\n\n            boolean bool = signature.verify(result);\n\n            System.out.println(\"jdk rsa verify:\" + bool);\n\n        } catch (Exception e) {\n\n            System.out.println(e.toString());\n\n        }\n\n    }\n\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">RSA\u7684\u5e94\u7528\u573a\u666f\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2017\/06\/0170621113226.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2017\/06\/0170621113226.png\" alt=\"0170621113226\" width=\"678\" height=\"238\" class=\"alignnone size-full wp-image-2047\"><\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u53c2\u8003:<\/p>\n<p style=\"margin: 1em 0px;\"><a id=\"cb_post_title_url\" href=\"http:\/\/www.cnblogs.com\/jfzhu\/p\/4020097.html\">Base 64 \u7f16\u7801<\/a><\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"http:\/\/blog.csdn.net\/a394268045\/article\/details\/52232120\">RSA\u975e\u5bf9\u79f0\u52a0\u5bc6\u8be6\u89e3<\/a><\/p>\n<p style=\"margin: 1em 0px;\"><a id=\"viewpost1_TitleUrl\" class=\"postTitle2\" href=\"http:\/\/www.blogjava.net\/amigoxie\/archive\/2014\/06\/01\/414299.html\">\u5355\u5411\u52a0\u5bc6\u7b97\u6cd5MD5\u548cSHA<\/a><\/p>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1a\u8981\u4fdd\u5bc6\u7528\u5bf9\u79f0\/\u975e\u5bf9\u79f0\uff1b\u8981\u6821\u9a8c\u7528\u6458\u8981\uff1b\u8981\u9632\u62b5\u8d56\u7528\u7b7e\u540d\u3002Base64 \u53ea\u662f\u7f16\u7801\uff0c\u522b\u5f53\u6210\u52a0\u5bc6\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u52a0\u5bc6\u5c31\u662f\u628a\u660e\u6587\u53d8\u6210\u8def\u4e0a\u622a\u83b7\u4e5f\u770b\u4e0d\u61c2\u7684\u4e1c\u897f\uff0c\u9001\u5230\u63a5\u6536\u65b9\u540e\u518d\u7528\u914d\u5957\u7b97\u6cd5\u8fd8\u539f\u3002Java \u91cc\u5e38\u7528\u7684\u51e0\u7c7b\u662f \u5bf9\u79f0\u52a0\u5bc6\u3001\u975e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3498,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[59],"tags":[57],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2028"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2028"}],"version-history":[{"count":3,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2028\/revisions"}],"predecessor-version":[{"id":3904,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2028\/revisions\/3904"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/media\/3498"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}