{"id":1439,"date":"2022-12-01T19:30:44","date_gmt":"2022-12-01T11:30:44","guid":{"rendered":"http:\/\/175.24.184.226\/?p=1439"},"modified":"2022-12-01T19:30:44","modified_gmt":"2022-12-01T11:30:44","slug":"%e5%89%8d%e7%ab%af%e5%8a%a0%e5%af%86js%e5%ba%93-cryptojs-%e4%bd%bf%e7%94%a8%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"\/?p=1439","title":{"rendered":"\u524d\u7aef\u52a0\u5bc6JS\u5e93&#8211;CryptoJS \u4f7f\u7528\u6307\u5357"},"content":{"rendered":"<h2>1.\u6982\u8ff0<\/h2>\n<p>\u6709\u65f6\u5019\u9879\u76ee\u6d89\u53ca\u5230\u7684\u654f\u611f\u6570\u636e\u6bd4\u8f83\u591a\uff0c\u4e3a\u4e86\u4fe1\u606f\u5b89\u5168\uff0c\u6211\u4eec\u5e38\u5e38\u9700\u8981\u5bf9\u4e00\u4e9b\u6570\u636e\u8fdb\u884c\u63a5\u53e3\u52a0\u5bc6\u5904\u7406\uff0c\u5982\u7f16\u7801\u3001\u5c06\u660e\u6587\u8f6c\u5316\u4e3a\u6697\u6587\u3001\u52a0\u5bc6\u6bd4\u5bf9\u3001AES + BASE64 \u7b97\u6cd5\u52a0\u5bc6\u7b49\u3002<br \/>\n\u63a5\u4e0b\u6765\u6211\u4eec\u5c31\u5206\u522b\u8bf4\u4e00\u4e0b CryptoJS \u5e38\u7528\u7684\u4e00\u4e9b\u65b9\u6cd5\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/brix\/crypto-js\">CryptoJS\u6587\u6863<\/a><\/p>\n<p><strong>\u4e3a\u4ec0\u4e48\u8981\u7f16\u7801\uff1f<\/strong><\/p>\n<p>\u7531\u4e8e\u4e00\u4e9b\u7f51\u7edc\u901a\u8baf\u534f\u8bae\u7684\u9650\u5236, \u53c8\u6216\u8005\u662f\u51fa\u4e8e\u4fe1\u606f\u52a0\u5bc6\u7684\u76ee\u7684, \u6211\u4eec\u5c31\u9700\u8981\u5c06\u539f\u4fe1\u606f\u8f6c\u6362\u4e3abase64\u7f16\u7801,\u7136\u540e\u624d\u80fd\u8fdb\u884c\u4f20\u8f93.\u4f8b\u5982\uff0c\u53d1\u9001\u67d0\u4e9b\u542b\u6709 ASCII \u7801\u8868\u4e2d0\u523031\u4e4b\u95f4\u7684\u63a7\u5236\u5b57\u7b26\u7684\u6570\u636e\u3002<\/p>\n<p><strong>window.btoa \u5bf9\u5b57\u7b26\u4e32\u8fdb\u884c base64\u7f16\u7801\uff08\u6ce8\u610f\u4e0d\u80fd\u7f16\u7801\u4e2d\u6587\uff09;<\/strong><br \/>\n<strong>winodw.atob \u5bf9 base64\u5b57\u7b26\u4e32 \u8fdb\u884c\u89e3\u7801\uff08\u5bf9\u4e8e\u5305\u542b\u4e2d\u6587\u7684 base64\u7f16\u7801\uff0c\u4e0d\u80fd\u6b63\u786e\u89e3\u7801\uff09;<\/strong><\/p>\n<p>\u901a\u5e38\u7684\u65b9\u6cd5\u662f\u901a\u8fc7 window.btoa() \u65b9\u6cd5\u5bf9\u6e90\u6570\u636e\u8fdb\u884c\u7f16\u7801, \u7136\u540e\u63a5\u6536\u65b9\u4f7f\u7528 window.atob() \u65b9\u6cd5\u5bf9\u5176\u8fdb\u884c\u89e3\u7801, \u4ece\u800c\u5f97\u5230\u539f\u6570\u636e\u3002\u4f46\u662f\u8fd9\u79cd\u65b9\u6cd5\u5b58\u5728\u7684\u95ee\u9898\u662f\uff1awindow.btoa() \u4e0d\u652f\u6301\u4e2d\u6587, window.atob() \u8f6c\u6362\u542b\u6709\u4e2d\u6587\u7684 base64\u7f16\u7801 \u7684\u65f6\u5019\u4e2d\u6587\u90e8\u5206\u4f1a\u53d8\u4e3a\u4e71\u7801\u3002\u53e6\u4e00\u4e2a\u5b58\u5728\u7684\u95ee\u9898\u662f\u89e3\u7801github\u7684readme\u6570\u636e\u7684\u65f6\u5019\u4e5f\u662f\u4e71\u7801\u3002\u7ecf\u8fc7\u67e5\u627e\u76f8\u5173\u8d44\u6599\u53d1\u73b0\u4e86 Base64\u7684\u7f16\u7801\u4e0e\u89e3\u7801\u8f6c\u7684\u6700\u4f18\u65b9\u6848:<\/p>\n<pre><code class=\"language-javascript\">\/\/ \u7f16\u7801\nfunction utf8_to_b64(str) {\n    return window.btoa(unescape(encodeURIComponent(str)));\n}\n\n\/\/ \u89e3\u7801\nfunction b64_to_utf8(str) {\n    return decodeURIComponent(escape(window.atob(str)));\n}\n\n\/\/ Usage:\nutf8_to_b64(&#039;\u2713 \u00e0 la mode&#039;); \/\/ 4pyTIMOgIGxhIG1vZGU=\nb64_to_utf8(&#039;4pyTIMOgIGxhIG1vZGU=&#039;); \/\/ &quot;\u2713 \u00e0 la mode&quot;\n\nutf8_to_b64(&#039;I u2661 Unicode!&#039;); \/\/ SSDimaEgVW5pY29kZSE=\nb64_to_utf8(&#039;SSDimaEgVW5pY29kZSE=&#039;); \/\/ &quot;I \u2661 Unicode!&quot;\n\nutf8_to_b64(&#039;\u6211\u7231\u4e2d\u56fd&#039;); \/\/ 5oiR54ix5Lit5Zu9\nb64_to_utf8(&#039;SSDimaEgVW5pY29kZSE=&#039;); \/\/ &quot;\u6211\u7231\u4e2d\u56fd&quot;\n\nutf8_to_b64(123456); \/\/ MTIzNDU2\nb64_to_utf8(&quot;MTIzNDU2&quot;); \/\/ 123456<\/code><\/pre>\n<h2>2.AES \u52a0\u5bc6<\/h2>\n<h3>2.1\u5b89\u88c5<code>crypto-js<\/code><\/h3>\n<pre><code>$ npm install crypto-js<\/code><\/pre>\n<p><code>aes\u52a0\u5bc6: crypto.js<\/code><\/p>\n<pre><code class=\"language-javascript\">import CryptoJS from &quot;crypto-js&quot;;\n\nconst key = CryptoJS.enc.Utf8.parse(&quot;1234567890000000&quot;); \/\/16\u4f4d\nconst iv = CryptoJS.enc.Utf8.parse(&quot;1234567890000000&quot;);\n\nexport default {\n  \/\/aes\u52a0\u5bc6\n  encrypt(word) {\n    let encrypted = &quot;&quot;;\n    if (typeof word == &quot;string&quot;) {\n      const srcs = CryptoJS.enc.Utf8.parse(word);\n      encrypted = CryptoJS.AES.encrypt(srcs, key, {\n        iv: iv,\n        mode: CryptoJS.mode.CBC,\n        padding: CryptoJS.pad.Pkcs7\n      });\n    } else if (typeof word == &quot;object&quot;) {\n      \/\/\u5bf9\u8c61\u683c\u5f0f\u7684\u8f6c\u6210json\u5b57\u7b26\u4e32\n      const data = JSON.stringify(word);\n      const srcs = CryptoJS.enc.Utf8.parse(data);\n      encrypted = CryptoJS.AES.encrypt(srcs, key, {\n        iv: iv,\n        mode: CryptoJS.mode.CBC,\n        padding: CryptoJS.pad.Pkcs7\n      });\n    }\n    return encrypted.ciphertext.toString();\n  },\n  \/\/ aes\u89e3\u5bc6\n  decrypt(word) {\n    const encryptedHexStr = CryptoJS.enc.Hex.parse(word);\n    const srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);\n    const decrypt = CryptoJS.AES.decrypt(srcs, key, {\n      iv: iv,\n      mode: CryptoJS.mode.CBC,\n      padding: CryptoJS.pad.Pkcs7\n    });\n    const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);\n    return decryptedStr.toString();\n  }\n};<\/code><\/pre>\n<h3>2.2\u4f7f\u7528<\/h3>\n<pre><code class=\"language-javascript\">import Crypto from &quot;@\/utils\/crypto&quot;;\n\nCrypto.encrypt(&quot;\u2713 \u00e0 la mode&quot;); \/\/ b915bf40c4795227488da86978f55fce\nCrypto.decrypt(userPwd); \/\/ &quot;\u2713 \u00e0 la mode&quot;\n\nCrypto.encrypt(&quot;\u2713 \u00e0 la mode&quot;); \/\/ 6317313288b32bf1909f165ec530d60a\nCrypto.decrypt(userPwd); \/\/ &quot;I \u2661 Unicode!&quot;\n\nCrypto.encrypt(&quot;\u6211\u7231\u4e2d\u56fd&quot;); \/\/ 1898a34273855f55255437aa22f87504\nCrypto.decrypt(userPwd); \/\/ &quot;\u6211\u7231\u4e2d\u56fd&quot;\n\nCrypto.encrypt(&quot;123456&quot;); \/\/ dd7a6c4edc68e683b700a7a2846a2bc6\nCrypto.decrypt(userPwd); \/\/ &quot;123456&quot;<\/code><\/pre>\n<h3>2.3\u524d\u540e\u7aef\u6570\u636e\u901a\u4fe1\u53c2\u6570\u52a0\u5bc6<\/h3>\n<p>\u52a0\u5bc6\u4ee3\u7801\u5b9e\u73b0:<\/p>\n<p>\u9879\u76ee\u4e2d\u9700\u8981\u5c06\u6240\u6709\u4f20\u5230\u540e\u53f0\u7684\u53c2\u6570\u52065\u4e2a\u6b65\u9aa4\u5904\u7406\uff1a<\/p>\n<p>\u7b2c\u4e00\u6b65\uff1a\u6392\u5e8f<\/p>\n<p>\u7b2c\u4e8c\u6b65\uff1a\u5c06\u6392\u5e8f\u597d\u7684\u53c2\u6570\u8fdb\u884cMD5\u52a0\u5bc6\u4f5c\u4e3a\u63a5\u53e3\u7684\u7b7e\u540d<\/p>\n<p>\u7b2c\u4e09\u6b65\uff1a\u5c06\u6392\u5e8f\u597d\u7684\u53c2\u6570\u548c\u63a5\u53e3\u7b7e\u540d\u62fc\u63a5\u4e0a\u8fdb\u884cAES\u52a0\u5bc6<\/p>\n<p>\u7b2c\u56db\u90e8\uff1a\u5c06AES\u52a0\u5bc6\u540e\u7684\u5bc6\u6587Base64\u52a0\u5bc6<\/p>\n<p>\u7b2c\u4e94\u6b65\uff1a\u5c06\u6700\u7ec8\u7684\u5bc6\u6587encodeURIComponent\uff1b<\/p>\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-javascript\">function encryption(data) {\n    let strs=[];\n    for(let i in data){\n        strs.push(i+&#039;=&#039;+data[i]);\n    }\n    strs.sort();  \/\/ \u6570\u7ec4\u6392\u5e8f\n    strs=strs.join(&#039;&amp;&#039;); \/\/ \u6570\u7ec4\u53d8\u5b57\u7b26\u4e32\n    let endData=strs+&#039;&amp;sign=&#039;+CryptoJS.MD5(strs+&#039;ADfj3kcadc2349akvm1CPFFCD84f&#039;).toString(); \/\/ MD5\u52a0\u5bc6\n    let key = CryptoJS.enc.Utf8.parse(&quot;0880076B18D7EE81&quot;); \/\/ \u52a0\u5bc6\u79d8\u94a5\n    let iv = CryptoJS.enc.Utf8.parse(&quot;CB3EC842D7C69578&quot;);  \/\/  \u77e2\u91cf\n    let encryptResult = CryptoJS.AES.encrypt(endData,key, {   \/\/  AES\u52a0\u5bc6\n        iv: iv,\n        mode: CryptoJS.mode.CBC,\n        padding: CryptoJS.pad.Pkcs7  \/\/ \u540e\u53f0\u7528\u7684\u662fpad.Pkcs5,\u524d\u53f0\u5bf9\u5e94\u4e3aPkcs7\n    });\n    return encodeURIComponent(CryptoJS.enc.Base64.stringify(encryptResult.ciphertext));  \/\/ Base64\u52a0\u5bc6encode;<\/code><\/pre>\n<p>\u52a0\u5bc6\u6700\u7ec8\u7684\u5bc6\u6587\u62fc\u63a5\u5728\u63a5\u53e3\u5730\u5740\u540e\u9762\uff0c\u8bf7\u6c42\u63a5\u53e3\u3002\u540e\u53f0\u8fd4\u56de\u7684\u6570\u636e\u4e5f\u662f\u5bc6\u6587\uff1b\u89e3\u5bc6\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-javascript\">function decryption(data) {\n    let key = CryptoJS.enc.Utf8.parse(&quot;0880076B18D7EE81&quot;);  \/\/ \u52a0\u5bc6\u79d8\u94a5\n    let iv = CryptoJS.enc.Utf8.parse(&quot;CB3EC842D7C69578&quot;);   \/\/  \u77e2\u91cf\n    let baseResult=CryptoJS.enc.Base64.parse(data);   \/\/ Base64\u89e3\u5bc6\n    let ciphertext=CryptoJS.enc.Base64.stringify(baseResult);     \/\/ Base64\u89e3\u5bc6\n    let decryptResult = CryptoJS.AES.decrypt(ciphertext,key, {    \/\/  AES\u89e3\u5bc6\n        iv: iv,\n        mode: CryptoJS.mode.CBC,\n        padding: CryptoJS.pad.Pkcs7\n    });\n    let resData=decryptResult.toString(CryptoJS.enc.Utf8).toString();\n\n    return JSON.parse(resData);\n}<\/code><\/pre>\n<p>\u5907\u6ce8\uff1a\u56e0\u4e3a\u540e\u53f0\u8fd4\u56de\u7684\u6570\u636e\u662fjson\u683c\u5f0f\uff1b\u6240\u4ee5\u505a\u79cdreturn\u7684\u65f6\u5019\u4f7f\u7528JSON.parse();\u5982\u679c\u89e3\u5bc6\u7684\u76ee\u6807\u4e3a\u5b57\u7b26\u4e32\uff0c\u6bd4\u5982\u8bf4\u9700\u8981\u89e3\u5bc6\u7684\u662f\u4e00\u4e2a\u52a0\u5bc6\u7684token\u503c\u3002\u90a3\u5c31\u8981\u505a\u76f8\u5e94\u7684\u6539\u52a8\uff1a<\/p>\n<pre><code class=\"language-javascript\">function decryption(data) {\n    let key = CryptoJS.enc.Utf8.parse(&quot;0880076B18D7EE81&quot;);  \/\/ \u52a0\u5bc6\u79d8\u94a5\n    let iv = CryptoJS.enc.Utf8.parse(&quot;CB3EC842D7C69578&quot;);   \/\/  \u77e2\u91cf\n    let baseResult=CryptoJS.enc.Base64.parse(data);   \/\/ Base64\u89e3\u5bc6\n    let ciphertext=CryptoJS.enc.Base64.stringify(baseResult);     \/\/ Base64\u89e3\u5bc6\n    let decryptResult = CryptoJS.AES.decrypt(ciphertext,key, {    \/\/  AES\u89e3\u5bc6\n        iv: iv,\n        mode: CryptoJS.mode.CBC,\n        padding: CryptoJS.pad.Pkcs7\n    });\n    return CryptoJS.enc.Utf8.stringify(decryptResult);\n}<\/code><\/pre>\n<h2>3.\u524d\u7aef crypto-js aes \u52a0\u89e3\u5bc6<\/h2>\n<h3>3.1\u80cc\u666f<\/h3>\n<p>\u524d\u6bb5\u65f6\u95f4\u516c\u53f8\u505a\u9879\u76ee\uff0c\u8be5\u9879\u76ee\u6d89\u53ca\u5230\u7684\u654f\u611f\u6570\u636e\u6bd4\u8f83\u591a\uff0c\u7ecf\u8fc7\u7684\u4e00\u6ce2\u8ba8\u8bba\u4e4b\u540e\uff0c\u51b3\u5b9a\u524d\u540e\u7aef\u8fdb\u884c\u63a5\u53e3\u52a0\u5bc6\u5904\u7406\uff0c\u91c7\u7528\u7684\u662f <code>AES<\/code> + <code>BASE64<\/code> \u7b97\u6cd5\u52a0\u5bc6~<\/p>\n<p>\u7f51\u4e0a\u5173\u4e8e <code>AES<\/code> \u5bf9\u79f0\u52a0\u5bc6\u7684\u7b97\u6cd5\u4ecb\u7ecd\u633a\u591a\u7684\uff0c\u5bf9\u8fd9\u4e00\u5757\u8fd8\u4e0d\u662f\u7279\u522b\u7406\u89e3\u7684\u5c0f\u4f19\u4f34\u53ef\u81ea\u884c\u767e\u5ea6\uff0c\u8fd9\u91cc\u6211\u63a8\u8350\u4e00\u7bc7<a href=\"https:\/\/link.jianshu.com\/?t=https%3A%2F%2Fblog.csdn.net%2Fqq_28205153%2Farticle%2Fdetails%2F55798628\">AES\u52a0\u5bc6\u7b97\u6cd5\u7684\u8be6\u7ec6\u4ecb\u7ecd\u4e0e\u5b9e\u73b0<\/a>\uff0c\u8bb2\u7684\u8fd8\u662f\u86ee\u8be6\u7ec6\u7684~<\/p>\n<h3>3.2\u5177\u4f53\u5b9e\u73b0<\/h3>\n<p>\u5176\u5b9e\u641e\u61c2\u4e86\u662f\u600e\u4e48\u4e00\u56de\u4e8b\uff0c\u505a\u8d77\u6765\u8fd8\u662f\u633a\u7b80\u5355\u7684\uff0c\u56e0\u4e3a\u5e93\u90fd\u662f\u73b0\u6210\u7684\uff0c\u6211\u4eec\u53ea\u9700\u8981\u4f1a\u7528\u5c31\u597d\u5566\uff0c\u8fd9\u91cc\u6211\u5728\u63a8\u8350\u4e00\u7bc7<a href=\"https:\/\/link.jianshu.com\/?t=https%3A%2F%2Fblog.csdn.net%2Fvieri_32%2Farticle%2Fdetails%2F48345023\">\u7406\u89e3AES\u52a0\u5bc6\u89e3\u5bc6\u7684\u4f7f\u7528\u65b9\u6cd5<\/a>\uff0c\u52a0\u6df1\u5927\u5bb6\u5bf9 <code>AES<\/code> \u7b97\u6cd5\u7684\u7406\u89e3~<\/p>\n<p>\u8fd9\u91cc\u6211\u4ee5 <code>Vue<\/code> \u4f5c\u4e3a\u4f8b\u5b50\uff0c\u5176\u4ed6\u7684\u4e5f\u5c31\u5927\u540c\u5c0f\u5f02\u4e86~<\/p>\n<ul>\n<li>\u8981\u7528 <code>AES<\/code> \u7b97\u6cd5\u52a0\u5bc6\uff0c\u9996\u5148\u6211\u4eec\u8981\u5f15\u5165 <code>crypto-js<\/code> \uff0c<code>crypto-js<\/code> \u662f\u4e00\u4e2a\u7eaf <code>javascript<\/code> \u5199\u7684\u52a0\u5bc6\u7b97\u6cd5\u7c7b\u5e93 \uff0c\u53ef\u4ee5\u975e\u5e38\u65b9\u4fbf\u5730\u5728 <code>javascript<\/code> \u8fdb\u884c <code>MD5<\/code>\u3001<code>SHA1<\/code>\u3001<code>SHA2<\/code>\u3001<code>SHA3<\/code>\u3001<code>RIPEMD-160<\/code> \u54c8\u5e0c\u6563\u5217\uff0c\u8fdb\u884c <code>AES<\/code>\u3001<code>DES<\/code>\u3001<code>Rabbit<\/code>\u3001<code>RC4<\/code>\u3001<code>Triple DES<\/code> \u52a0\u89e3\u5bc6\uff0c\u6211\u4eec\u53ef\u4ee5\u91c7\u7528 <code>npm install crypto-js --save<\/code> \u8fdb\u884c\u4e0b\u8f7d\u5b89\u88c5\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u53bb <a href=\"https:\/\/link.jianshu.com\/?t=https%3A%2F%2Fgithub.com%2Fbrix%2Fcrypto-js\">GitHub<\/a>\u4e0b\u8f7d\u6e90\u7801~<\/li>\n<li>\u5176\u6b21\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e24\u4e2a\u65b9\u6cd5 \uff0c\u5206\u522b\u662f\u7528\u4e8e\u52a0\u5bc6\u548c\u89e3\u5bc6\uff0c\u8fd9\u91cc\u6211\u5c06\u5b83\u653e\u5728\u4e86 <code>utils<\/code> \u6587\u4ef6\u5939\u4e0b\uff0c\u547d\u540d\u4e3a <code>secret.js<\/code> \uff0c\u5176\u5177\u4f53\u4ee3\u7801\u5982\u4e0b\uff1a<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">const CryptoJS = require(&#039;crypto-js&#039;);  \/\/\u5f15\u7528AES\u6e90\u7801js\n\nconst key = CryptoJS.enc.Utf8.parse(&quot;1234123412ABCDEF&quot;);  \/\/\u5341\u516d\u4f4d\u5341\u516d\u8fdb\u5236\u6570\u4f5c\u4e3a\u5bc6\u94a5\nconst iv = CryptoJS.enc.Utf8.parse(&#039;ABCDEF1234123412&#039;);   \/\/\u5341\u516d\u4f4d\u5341\u516d\u8fdb\u5236\u6570\u4f5c\u4e3a\u5bc6\u94a5\u504f\u79fb\u91cf\n\n\/\/\u89e3\u5bc6\u65b9\u6cd5\nfunction Decrypt(word) {\n    let encryptedHexStr = CryptoJS.enc.Hex.parse(word);\n    let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);\n    let decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });\n    let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);\n    return decryptedStr.toString();\n}\n\n\/\/\u52a0\u5bc6\u65b9\u6cd5\nfunction Encrypt(word) {\n    let srcs = CryptoJS.enc.Utf8.parse(word);\n    let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });\n    return encrypted.ciphertext.toString().toUpperCase();\n}\n\nexport default {\n    Decrypt ,\n    Encrypt\n}<\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\u7684 <code>key<\/code> \u662f\u5bc6\u94a5 \uff0c<code>iv<\/code> \u662f\u5bc6\u94a5\u504f\u79fb\u91cf\uff0c\u8fd9\u4e2a\u4e00\u822c\u662f\u63a5\u53e3\u8fd4\u56de\u7684\uff0c\u4e3a\u4e86\u65b9\u4fbf\uff0c\u6211\u4eec\u8fd9\u91cc\u5c31\u76f4\u63a5\u5728\u8fd9\u91cc\u5b9a\u4e49\u4e86\u3002<\/p>\n<p>\u503c\u5f97\u6ce8\u610f\u7684\u662f\u5bc6\u94a5\u7684\u957f\u5ea6\uff0c\u7531\u4e8e\u5bf9\u79f0\u89e3\u5bc6\u4f7f\u7528\u7684\u7b97\u6cd5\u662f <code>AES-128-CBC<\/code>\u7b97\u6cd5\uff0c\u6570\u636e\u91c7\u7528 <code>PKCS#7<\/code> \u586b\u5145 \uff0c \u56e0\u6b64\u8fd9\u91cc\u7684 <code>key<\/code> \u9700\u8981\u4e3a16\u4f4d\uff01<\/p>\n<p>\u63a5\u7740\u6211\u4eec\u5b9a\u4e49\u4e86 <strong>\u89e3\u5bc6\u65b9\u6cd5<code>Decrypt<\/code><\/strong> \u548c <strong>\u52a0\u5bc6\u65b9\u6cd5 <code>Encrypt<\/code><\/strong> \uff0c\u6700\u540e\u901a\u8fc7 <code>export default<\/code> \u5c06\u5176\u66b4\u9732\u51fa\u53bb\uff0c\u65b9\u4fbf\u5728\u9700\u8981\u7684\u65f6\u5019\u8fdb\u884c\u5f15\u5165~<\/p>\n<p>ok\uff0c\u6838\u5fc3\u4ee3\u7801\u5c31\u8fd9\u4e48\u591a\uff0c\u662f\u4e0d\u662f\u5f88\u7b80\u5355\u554a\uff0c\u5176\u5b9e\u4e5f\u4e48\u6709\u4f60\u60f3\u7684\u90a3\u4e48\u590d\u6742\u54c8\uff0c\u5269\u4e0b\u7684\u5c31\u662f\u5c55\u793a\u4e00\u4e0b\u5982\u4f55\u4f7f\u7528\u54af~<\/p>\n<h3>3.3\u793a\u4f8b<\/h3>\n<p>\u8fd9\u91cc\u6211\u5b9a\u4e49\u4e86\u4e00\u4e2a <code>index.vue<\/code> \u7528\u6765\u5c55\u793a\u6570\u636e\u52a0\u89e3\u5bc6\u7684\u64cd\u4f5c~<\/p>\n<p><strong>\u52a0\u5bc6\u64cd\u4f5c\uff1a<\/strong> \u5047\u8bbe\u6211\u4eec\u73b0\u5728\u8981\u7ed9\u540e\u7aef\u53d1\u9001\u4e00\u6bb5\u6587\u5b57\uff0c\u6682\u4e14\u5b9a\u4e49\u4e3a <code>This is a clear text<\/code> \uff0c \u5728\u53d1\u9001\u4e4b\u524d\u6211\u4eec\u9700\u8981\u5bf9\u5176\u8fdb\u884c\u52a0\u5bc6\u64cd\u4f5c\uff0c\u8fd9\u65f6\u5019\u6211\u4eec\u53ef\u4ee5\u8c03\u7528\u4e0a\u9762\u4ecb\u7ecd\u7684 <code>Encrypt<\/code> \u65b9\u6cd5\uff0c\u901a\u8fc7\u52a0\u5bc6\u540e\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u5bc6\u6587\u4e3a\uff1a<code>4ACEA01505ADAF9FB59A03B22FC1EF1B244AE28DDACFDFAEFA7E263655C44357<\/code><\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202212011928483.webp\" alt=\"img\" \/><\/p>\n<p><strong>\u89e3\u5bc6\u64cd\u4f5c\uff1a<\/strong> \u5047\u8bbe\u6211\u4eec\u8bf7\u6c42\u540e\u7aef\u63a5\u53e3\uff0c\u540e\u7aef\u8fd4\u56de\u4e86\u6211\u4eec\u4e00\u5806\u5982\u4e0b\u7684\u5b57\u7b26\u4e32 <code>BBFE62335C28821AD2F4043B715BB0C3E45734908254666526DCFD86A605F3AF<\/code> , \u8fd9\u8ba9\u6211\u5f88\u8499\u853d\u554a\uff0c\u8fd9\u65f6\u5019\u5c31\u8981\u8c03\u7528 <code>Decrypt<\/code> \u65b9\u6cd5\uff0c<br \/>\n\u901a\u8fc7\u89e3\u5bc6\u6211\u4eec\u53ef\u4ee5\u62ff\u5230\u540e\u7aef\u8fd4\u56de\u7684\u4fe1\u606f\u5176\u5b9e\u662f\uff1a<code>{&quot;name&quot;:&quot;Chris&quot;,&quot;sex&quot;:&quot;male&quot;}<\/code><\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202212011929180.webp\" alt=\"img\" \/><\/p>\n<h2>4.\u7ed3\u8bed<\/h2>\n<p>\u81f3\u6b64\uff0c\u4f60\u5df2\u7ecf <code>get<\/code> \u4e86\u524d\u7aef <code>AES<\/code> \u52a0\u89e3\u5bc6\u7684\u65b9\u6cd5\uff0c\u662f\u4e0d\u662f\u611f\u89c9\u5f88\u7b80\u5355\u554a\uff0c\u7528\u8d77\u6765\u5f88\u7b80\u5355\uff0c\u539f\u7406\u53ef\u4e0d\u7b80\u5355\uff0c\u51b5\u4e14\u8fd9\u4e5f\u53ea\u662f\u5176\u4e2d\u7684\u4e00\u79cd\u65b9\u6848\uff0c\u5173\u4e8e\u52a0\u89e3\u5bc6\u7684\u65b9\u6cd5\u8fd8\u6709\u5f88\u591a\uff0c\u611f\u5174\u8da3\u7684\u5c0f\u4f19\u4f34\u4eec\u53ef\u4ee5\u7ee7\u7eed\u505a\u4e00\u4e9b\u6df1\u5165\u7684\u7814\u7a76\u54c8~<\/p>\n<p>\u63a8\u8350\u4e00\u7bc7\u4f7f\u7528\u6587\u7ae0 <a href=\"https:\/\/www.cnblogs.com\/June2005\/p\/11429442.html\">https:\/\/www.cnblogs.com\/June2005\/p\/11429442.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u6982\u8ff0 \u6709\u65f6\u5019\u9879\u76ee\u6d89\u53ca\u5230\u7684\u654f\u611f\u6570\u636e\u6bd4\u8f83\u591a\uff0c\u4e3a\u4e86\u4fe1\u606f\u5b89\u5168\uff0c\u6211\u4eec\u5e38\u5e38\u9700\u8981\u5bf9\u4e00\u4e9b\u6570\u636e\u8fdb\u884c\u63a5\u53e3\u52a0\u5bc6\u5904\u7406\uff0c\u5982\u7f16\u7801\u3001\u5c06\u660e\u6587\u8f6c\u5316\u4e3a\u6697\u6587\u3001\u52a0\u5bc6\u6bd4\u5bf9\u3001A   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[125],"tags":[78],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1439"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1439"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1439\/revisions"}],"predecessor-version":[{"id":1440,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1439\/revisions\/1440"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1439"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}