{"id":72659,"date":"2026-02-06T10:49:44","date_gmt":"2026-02-06T02:49:44","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/72659.html"},"modified":"2026-02-06T10:49:44","modified_gmt":"2026-02-06T02:49:44","slug":"vue3%e4%b8%ad%e4%bd%bf%e7%94%a8crypto-js%e5%8a%a0%e5%af%86-%e8%a7%a3%e5%af%86%e5%b0%81%e8%a3%85%e5%8a%a0%e5%af%86%e5%b7%a5%e5%85%b7","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/72659.html","title":{"rendered":"vue3\u4e2d\u4f7f\u7528crypto-js\u52a0\u5bc6\/\u89e3\u5bc6&amp;&amp;\u5c01\u88c5\u52a0\u5bc6\u5de5\u5177"},"content":{"rendered":"<h5>\u5728 CryptoJS \u5e93\u4e2d&#xff0c;Base64\u3001MD5 \u548c AES \u662f\u4e09\u79cd\u4e0d\u540c\u6027\u8d28\u7684\u7f16\u7801\u6216\u52a0\u5bc6\u65b9\u6cd5&#xff0c;\u5b83\u4eec\u5728\u539f\u7406\u3001\u7528\u9014\u548c\u5b89\u5168\u6027\u4e0a\u6709\u672c\u8d28\u533a\u522b<\/h5>\n<h5>\u7279\u6027\u00a0<\/h5>\n<h5>Base64\u00a0\u00a0\u4e0d\u5b89\u5168&#xff08;\u4ec5\u7f16\u7801&#xff09;\u5e38\u7528\u4e8e\u6570\u636e\u683c\u5f0f\u8f6c\u6362&#xff0c;\u8f93\u51fa\u5f62\u5f0f\u662f\u6587\u672c\u5b57\u7b26\u4e32<\/h5>\n<h5>\u00a0MD5\u00a0\u4e0d\u5b89\u5168&#xff08;\u54c8\u5e0c&#xff09; \u5e38\u7528\u4e8e\u5b8c\u6574\u6027\u6821\u9a8c\u3001\u65e7\u5bc6\u7801\u5b58\u50a8&#xff0c;\u8f93\u51fa\u5f62\u5f0f\u662f32\u4f4d\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32<\/h5>\n<h5>AES\u00a0\u5b89\u5168&#xff08;\u5bf9\u79f0\u52a0\u5bc6&#xff09;\u5e38\u7528\u4e8e\u4fdd\u5bc6\u6570\u636e\u4f20\u8f93\u4e0e\u5b58\u50a8&#xff0c;\u8f93\u51fa\u5f62\u5f0f\u662f\u4e8c\u8fdb\u5236\u6570\u636e<\/h5>\n<h5 id=\"druv3\">\u5b89\u88c5 crypto-js<\/h5>\n<p>npm install crypto-js &#8211;save<\/p>\n<p>Vue 3 \u7ec4\u4ef6\u4e2d\u4f7f\u7528crypto-js\u8fdb\u884c AES \u52a0\u5bc6\u548c\u89e3\u5bc6<\/p>\n<p>&lt;template&gt;<\/p>\n<p>\u00a0 &lt;div&gt;<\/p>\n<p>\u00a0 \u00a0 &lt;input v-model&#061;&#034;plaintext&#034; placeholder&#061;&#034;\u8f93\u5165\u8981\u52a0\u5bc6\u7684\u6587\u672c&#034; \/&gt;<\/p>\n<p>\u00a0 \u00a0 &lt;button &#064;click&#061;&#034;encrypt&#034;&gt;\u52a0\u5bc6&lt;\/button&gt;<\/p>\n<p>\u00a0 \u00a0 &lt;button &#064;click&#061;&#034;decrypt&#034;&gt;\u89e3\u5bc6&lt;\/button&gt;<\/p>\n<p>\u00a0 \u00a0 &lt;p&gt;\u52a0\u5bc6\u540e\u7684\u6587\u672c: {{ ciphertext }}&lt;\/p&gt;<\/p>\n<p>\u00a0 \u00a0 &lt;p&gt;\u89e3\u5bc6\u540e\u7684\u6587\u672c: {{ decryptedText }}&lt;\/p&gt;<\/p>\n<p>\u00a0 &lt;\/div&gt;<\/p>\n<p>&lt;\/template&gt;<\/p>\n<p>&lt;script setup&gt;<\/p>\n<p>\u00a0 import { ref } from &#039;vue&#039;<\/p>\n<p>\u00a0 import CryptoJS from &#039;crypto-js&#039;<\/p>\n<\/p>\n<p>\u00a0 defineProps({<\/p>\n<p>\u00a0 \u00a0 msg: String,<\/p>\n<p>\u00a0 })<\/p>\n<\/p>\n<p>\u00a0 const count &#061; ref(0)<\/p>\n<p>\u00a0 \/\/ 1. \u5b9a\u4e49\u54cd\u5e94\u5f0f\u6570\u636e&#xff08;\u66ff\u4ee3\u9009\u9879\u5f0fAPI\u7684data&#xff09;<\/p>\n<p>\u00a0 const plaintext &#061; ref(&#039;&#039;) \/\/ \u539f\u59cb\u6587\u672c<\/p>\n<p>\u00a0 const ciphertext &#061; ref(&#039;&#039;) \/\/ \u52a0\u5bc6\u540e\u7684\u6587\u672c<\/p>\n<p>\u00a0 const decryptedText &#061; ref(&#039;&#039;) \/\/ \u89e3\u5bc6\u540e\u7684\u6587\u672c<\/p>\n<\/p>\n<p>\u00a0 \/\/ 2. \u5b9a\u4e49\u52a0\u5bc6\u51fd\u6570&#xff08;\u66ff\u4ee3\u9009\u9879\u5f0fAPI\u7684methods&#xff09;<\/p>\n<p>\u00a0 const encrypt &#061; () &#061;&gt; {<\/p>\n<p>\u00a0 \u00a0 const secretKey &#061; &#039;your-secret-key&#039; \/\/ \u5efa\u8bae\u66ff\u6362\u4e3a\u81ea\u5df1\u7684\u5bc6\u94a5<\/p>\n<p>\u00a0 \u00a0 \/\/ AES\u52a0\u5bc6\u5e76\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32<\/p>\n<p>\u00a0 \u00a0 ciphertext.value &#061; CryptoJS.AES.encrypt(<\/p>\n<p>\u00a0 \u00a0 \u00a0 plaintext.value,<\/p>\n<p>\u00a0 \u00a0 \u00a0 secretKey,<\/p>\n<p>\u00a0 \u00a0 ).toString()<\/p>\n<p>\u00a0 }<\/p>\n<\/p>\n<p>\u00a0 \/\/ 3. \u5b9a\u4e49\u89e3\u5bc6\u51fd\u6570<\/p>\n<p>\u00a0 const decrypt &#061; () &#061;&gt; {<\/p>\n<p>\u00a0 \u00a0 const secretKey &#061; &#039;your-secret-key&#039; \/\/ \u5fc5\u987b\u548c\u52a0\u5bc6\u5bc6\u94a5\u4e00\u81f4<\/p>\n<p>\u00a0 \u00a0 try {<\/p>\n<p>\u00a0 \u00a0 \u00a0 \/\/ \u89e3\u5bc6\u5e76\u8f6c\u6362\u4e3aUTF8\u5b57\u7b26\u4e32<\/p>\n<p>\u00a0 \u00a0 \u00a0 const bytes &#061; CryptoJS.AES.decrypt(ciphertext.value, secretKey)<\/p>\n<p>\u00a0 \u00a0 \u00a0 decryptedText.value &#061; bytes.toString(CryptoJS.enc.Utf8)<\/p>\n<p>\u00a0 \u00a0 } catch (error) {<\/p>\n<p>\u00a0 \u00a0 \u00a0 \/\/ \u6355\u83b7\u89e3\u5bc6\u5931\u8d25\u7684\u5f02\u5e38&#xff08;\u6bd4\u5982\u5bc6\u94a5\u9519\u8bef\u3001\u5bc6\u6587\u65e0\u6548&#xff09;<\/p>\n<p>\u00a0 \u00a0 \u00a0 decryptedText.value &#061; &#039;\u89e3\u5bc6\u5931\u8d25&#xff1a;\u5bc6\u6587\u65e0\u6548\u6216\u5bc6\u94a5\u9519\u8bef&#039;<\/p>\n<p>\u00a0 \u00a0 \u00a0 console.error(&#039;\u89e3\u5bc6\u51fa\u9519&#xff1a;&#039;, error)<\/p>\n<p>\u00a0 \u00a0 }<\/p>\n<p>\u00a0 }<\/p>\n<p>&lt;\/script&gt;<\/p>\n<\/p>\n<p>&lt;style scoped&gt;<\/p>\n<p>\u00a0 .read-the-docs {<\/p>\n<p>\u00a0 \u00a0 color: #888;<\/p>\n<p>\u00a0 }<\/p>\n<p>&lt;\/style&gt;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"285\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260206024943-698556c7b24e1.png\" width=\"813\" \/><\/p>\n<p><span style=\"color:#fe2c24\">\u5c01\u88c5\u52a0\u5bc6\u5de5\u5177<\/span>&#xff08;\u63a8\u8350\u653e\u5728 src\/utils\/crypto.js&#xff09;<\/p>\n<p><span style=\"color:#fe2c24\">1.\u5bfc\u5165 crypto-js \u5e93\u7684\u6838\u5fc3\u6a21\u5757&#xff0c;\u8be5\u5e93\u5c01\u88c5\u4e86\u6240\u6709\u4e3b\u6d41\u52a0\u5bc6\u7b97\u6cd5&#xff08;AES\u3001MD5\u3001SHA \u7b49&#xff09;&#xff0c;\u65e0\u9700\u81ea\u5df1\u5b9e\u73b0\u590d\u6742\u7684\u52a0\u5bc6\u903b\u8f91&#xff1b;<\/span><\/p>\n<p><span style=\"color:#fe2c24\">2.\u5fc5\u987b\u901a\u8fc7 npm install crypto-js \u5b89\u88c5\u8be5\u4f9d\u8d56&#xff0c;\u5426\u5219\u4f1a\u62a5 \u201c\u627e\u4e0d\u5230\u6a21\u5757\u201d \u9519\u8bef&#xff1b;<\/span><\/p>\n<p><span style=\"color:#fe2c24\">ciphertext&#xff1a;\u52a0\u5bc6\u540e\u7684\u5bc6\u6587\u5b57\u7b26\u4e32&#xff08;encryptAES \u7684\u8fd4\u56de\u503c&#xff09;<\/span><\/p>\n<p><span style=\"color:#fe2c24\">key&#xff1a;\u89e3\u5bc6\u5bc6\u94a5&#xff08;\u5fc5\u987b\u548c\u52a0\u5bc6\u5bc6\u94a5\u5b8c\u5168\u4e00\u81f4&#xff0c;\u5426\u5219\u89e3\u5bc6\u5931\u8d25&#xff09;<\/span><\/p>\n<p><span style=\"color:#fe2c24\">***!!!\u6ce8\u610f\u89e3\u5bc6\u65b9\u6cd5&#xff0c;\u53c2\u6570\u548c\u52a0\u5bc6\u5bf9\u5e94&#xff1a;\u5bc6\u6587\u3001\u89e3\u6790\u540e\u7684\u5bc6\u94a5\u3001\u76f8\u540c\u7684\u6a21\u5f0f \/ \u586b\u5145\u914d\u7f6e&#xff1b;<\/span><\/p>\n<p><span style=\"color:#ff9900\">AES \u52a0\u5bc6\u6838\u5fc3\u89c4\u5219\u5bc6\u94a5\u957f\u5ea6\u8981\u6c42&#xff1a;<\/span><\/p>\n<\/p>\n<ul>\n<li><span style=\"color:#ff9900\">AES-128&#xff1a;\u5bc6\u94a5\u5fc5\u987b 16 \u4f4d\u5b57\u7b26\u4e32&#xff08;\u6bd4\u5982 1234567890123456&#xff09;&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">AES-256&#xff1a;\u5bc6\u94a5\u5fc5\u987b 32 \u4f4d\u5b57\u7b26\u4e32&#xff08;\u6bd4\u5982 12345678901234561234567890123456&#xff09;&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">\u82e5\u5bc6\u94a5\u957f\u5ea6\u4e0d\u7b26\u5408&#xff0c;crypto-js \u4e0d\u4f1a\u62a5\u9519&#xff0c;\u4f46\u89e3\u5bc6\u4f1a\u5931\u8d25&#xff08;\u8fd4\u56de\u7a7a \/ \u4e71\u7801&#xff09;&#xff1b;<\/span><\/li>\n<\/ul>\n<p><span style=\"color:#ff9900\">\u586b\u5145\u7684\u4f5c\u7528:<\/span><\/p>\n<\/p>\n<ul>\n<li><span style=\"color:#ff9900\">AES \u662f\u5206\u7ec4\u52a0\u5bc6&#xff0c;\u6bcf\u6b21\u52a0\u5bc6 16 \u5b57\u8282&#xff08;128 \u4f4d&#xff09;\u7684\u660e\u6587\u5757&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">\u82e5\u660e\u6587\u957f\u5ea6\u4e0d\u662f 16 \u7684\u6574\u6570\u500d&#xff08;\u6bd4\u5982 \u201c\u6d4b\u8bd5\u201d \u662f 4 \u5b57\u8282&#xff09;&#xff0c;\u5fc5\u987b\u586b\u5145\u5230 16 \u5b57\u8282&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">PKCS7 \u586b\u5145\u89c4\u5219&#xff1a;\u7f3a N \u5b57\u8282\u5c31\u586b\u5145 N \u4e2a\u503c\u4e3a N \u7684\u5b57\u8282&#xff08;\u6bd4\u5982\u7f3a 12 \u5b57\u8282&#xff0c;\u586b\u5145 12 \u4e2a 0x0C&#xff09;&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">\u89e3\u5bc6\u65f6\u4f1a\u81ea\u52a8\u79fb\u9664\u586b\u5145\u7684\u5b57\u8282&#xff0c;\u8fd8\u539f\u539f\u59cb\u957f\u5ea6\u3002<\/span><\/li>\n<\/ul>\n<p><span style=\"color:#38d8f0\">import CryptoJS from &#039;crypto-js&#039;<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\/\/ AES\/ECB\/PKCS7Padding\u00a0\u52a0\u5bc6\u51fd\u6570 encryptAES<\/span><\/p>\n<p><span style=\"color:#38d8f0\">export function encryptAES(text, key) {<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\/\/ \u6b65\u9aa41&#xff1a;\u5c06\u5bc6\u94a5\u8f6c\u6362\u4e3a UTF8 \u7f16\u7801\u7684 WordArray \u683c\u5f0f<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\u00a0 const keyHex &#061; CryptoJS.enc.Utf8.parse(key)<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\/\/ \u6b65\u9aa42&#xff1a;\u6267\u884c AES \u52a0\u5bc6<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\u00a0 const encrypted &#061; CryptoJS.AES.encrypt(text, keyHex, {<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\u00a0 \u00a0 mode: CryptoJS.mode.ECB,<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\u00a0 \u00a0 padding: CryptoJS.pad.Pkcs7<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\u00a0 })<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\/\/ \u6b65\u9aa43&#xff1a;\u8fd4\u56de\u52a0\u5bc6\u540e\u7684\u5b57\u7b26\u4e32<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\u00a0 return encrypted.toString()<\/span><\/p>\n<p><span style=\"color:#38d8f0\">}<\/span><\/p>\n<\/p>\n<p><span style=\"color:#38d8f0\">\/\/ AES\/ECB\/PKCS7Padding \u89e3\u5bc6\u51fd\u6570 decryptAES<\/span><\/p>\n<p><span style=\"color:#38d8f0\">export function decryptAES(ciphertext, key) {<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\/\/ \u6b65\u9aa41&#xff1a;\u5c06\u5bc6\u94a5\u8f6c\u6362\u4e3a UTF8 \u7f16\u7801\u7684 WordArray \u683c\u5f0f&#xff08;\u548c\u52a0\u5bc6\u4e00\u81f4&#xff09;<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\u00a0 const keyHex &#061; CryptoJS.enc.Utf8.parse(key)<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\/\/ \u6b65\u9aa42&#xff1a;\u6267\u884c AES \u89e3\u5bc6<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\u00a0 const decrypted &#061; CryptoJS.AES.decrypt(ciphertext, keyHex, {<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\/\/ \u89e3\u5bc6\u6a21\u5f0f\u5fc5\u987b\u548c\u52a0\u5bc6\u4e00\u81f4<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\u00a0 \u00a0 mode: CryptoJS.mode.ECB,<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\/\/ \u586b\u5145\u65b9\u5f0f\u5fc5\u987b\u548c\u52a0\u5bc6\u4e00\u81f4<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\u00a0 \u00a0 padding: CryptoJS.pad.Pkcs7<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\u00a0 })<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\/\/ \u6b65\u9aa43&#xff1a;\u5c06\u89e3\u5bc6\u540e\u7684\u4e8c\u8fdb\u5236\u6570\u636e\u8f6c\u56de UTF8 \u5b57\u7b26\u4e32<\/span><\/p>\n<p><span style=\"color:#38d8f0\">\u00a0 return decrypted.toString(CryptoJS.enc.Utf8)<\/span><\/p>\n<p><span style=\"color:#38d8f0\">}<\/span><\/p>\n<p>Vue3 \u7ec4\u4ef6\u4e2d\u4f7f\u7528&#xff08;\u7ec4\u5408\u5f0f API&#xff09;<\/p>\n<p>&lt;template&gt;<\/p>\n<p>\u00a0 &lt;div&gt;<\/p>\n<p>\u00a0 \u00a0 &lt;input v-model&#061;&#034;plaintext&#034; placeholder&#061;&#034;\u8f93\u5165\u8981\u52a0\u5bc6\u7684\u6587\u672c&#034; \/&gt;<\/p>\n<p>\u00a0 \u00a0 &lt;button &#064;click&#061;&#034;encrypt&#034;&gt;\u52a0\u5bc6&lt;\/button&gt;<\/p>\n<p>\u00a0 \u00a0 &lt;button &#064;click&#061;&#034;decrypt&#034;&gt;\u89e3\u5bc6&lt;\/button&gt;<\/p>\n<p>\u00a0 \u00a0 &lt;p&gt;\u52a0\u5bc6\u540e\u7684\u6587\u672c: {{ ciphertext }}&lt;\/p&gt;<\/p>\n<p>\u00a0 \u00a0 &lt;p&gt;\u89e3\u5bc6\u540e\u7684\u6587\u672c: {{ decryptedText }}&lt;\/p&gt;<\/p>\n<p>\u00a0 &lt;\/div&gt;<\/p>\n<p>&lt;\/template&gt;<\/p>\n<\/p>\n<p>&lt;script setup&gt;<\/p>\n<p>\u00a0 import { ref } from &#039;vue&#039;<\/p>\n<p><span style=\"color:#fe2c24\">\u00a0 \/\/ \u5f15\u5165\u5c01\u88c5\u7684\u52a0\u89e3\u5bc6\u65b9\u6cd5&#xff08;\u786e\u4fdd&#064;\u522b\u540d\u5df2\u914d\u7f6e&#xff0c;crypto.js\u6587\u4ef6\u5b58\u5728&#xff09;<\/span><\/p>\n<p>\u00a0 <span style=\"color:#fe2c24\">\/\/ Vite \u4e0d\u4f1a\u9ed8\u8ba4\u8bc6\u522b &#064; \u4f5c\u4e3a src \u76ee\u5f55\u7684\u522b\u540d&#xff0c;\u9700\u8981\u624b\u52a8\u914d\u7f6e vite.config.js<\/span><\/p>\n<p>\u00a0 import { encryptAES, decryptAES } from &#039;&#064;\/utils\/crypto&#039;<\/p>\n<p>\u00a0 defineProps({<\/p>\n<p>\u00a0 \u00a0 msg: String,<\/p>\n<p>\u00a0 })<\/p>\n<p>\u00a0 const count &#061; ref(0)<\/p>\n<p>\u00a0 const plaintext &#061; ref(&#039;&#039;) \/\/ \u539f\u59cb\u6587\u672c<\/p>\n<p>\u00a0 const ciphertext &#061; ref(&#039;&#039;) \/\/ \u52a0\u5bc6\u540e\u7684\u6587\u672c<\/p>\n<p>\u00a0 const decryptedText &#061; ref(&#039;&#039;) \/\/ \u89e3\u5bc6\u540e\u7684\u6587\u672c<\/p>\n<\/p>\n<p>\u00a0 \/\/ 1. \u52a0\u5bc6\u65b9\u6cd5&#xff08;\u70b9\u51fb\u52a0\u5bc6\u6309\u94ae\u89e6\u53d1&#xff09;<\/p>\n<p>\u00a0 const encrypt &#061; () &#061;&gt; {<\/p>\n<p>\u00a0 \u00a0 \/\/ \u6821\u9a8c&#xff1a;\u786e\u4fdd\u8f93\u5165\u5185\u5bb9\u4e0d\u4e3a\u7a7a<\/p>\n<p>\u00a0 \u00a0 if (!plaintext.value.trim()) {<\/p>\n<p>\u00a0 \u00a0 \u00a0 alert(&#039;\u8bf7\u8f93\u5165\u8981\u52a0\u5bc6\u7684\u6587\u672c&#xff01;&#039;)<\/p>\n<p>\u00a0 \u00a0 \u00a0 return<\/p>\n<p>\u00a0 \u00a0 }<\/p>\n<\/p>\n<p>\u00a0 \u00a0 \/\/ \u5b9a\u4e49\u52a0\u5bc6\u5bc6\u94a5&#xff08;\u5efa\u8bae16\u4f4d\u621632\u4f4d&#xff0c;\u5b9e\u9645\u9879\u76ee\u4e0d\u8981\u786c\u7f16\u7801&#xff09;<\/p>\n<p>\u00a0 \u00a0 const secretKey &#061; &#039;1234567890123456&#039; \/\/ 16\u4f4d\u5bc6\u94a5&#xff08;AES-128&#xff09;<\/p>\n<\/p>\n<p>\u00a0 \u00a0 try {<\/p>\n<p>\u00a0 \u00a0 \u00a0 \/\/ \u8c03\u7528encryptAES\u65b9\u6cd5\u52a0\u5bc6<\/p>\n<p>\u00a0 \u00a0 \u00a0 ciphertext.value &#061; encryptAES(plaintext.value, secretKey)<\/p>\n<p>\u00a0 \u00a0 \u00a0 console.log(ciphertext.value)<\/p>\n<p>\u00a0 \u00a0 \u00a0 decryptedText.value &#061; &#039;&#039; \/\/ \u52a0\u5bc6\u540e\u6e05\u7a7a\u89e3\u5bc6\u7ed3\u679c<\/p>\n<p>\u00a0 \u00a0 } catch (error) {<\/p>\n<p>\u00a0 \u00a0 \u00a0 alert(&#039;\u52a0\u5bc6\u5931\u8d25&#xff1a;&#039; &#043; error.message)<\/p>\n<p>\u00a0 \u00a0 \u00a0 console.error(&#039;\u52a0\u5bc6\u9519\u8bef&#xff1a;&#039;, error)<\/p>\n<p>\u00a0 \u00a0 }<\/p>\n<p>\u00a0 }<\/p>\n<\/p>\n<p>\u00a0 \/\/ 2. \u89e3\u5bc6\u65b9\u6cd5&#xff08;\u70b9\u51fb\u89e3\u5bc6\u6309\u94ae\u89e6\u53d1&#xff09;<\/p>\n<p>\u00a0 const decrypt &#061; () &#061;&gt; {<\/p>\n<p>\u00a0 \u00a0 \/\/ \u6821\u9a8c&#xff1a;\u786e\u4fdd\u6709\u52a0\u5bc6\u540e\u7684\u5bc6\u6587<\/p>\n<p>\u00a0 \u00a0 if (!ciphertext.value.trim()) {<\/p>\n<p>\u00a0 \u00a0 \u00a0 alert(&#039;\u8bf7\u5148\u52a0\u5bc6\u751f\u6210\u5bc6\u6587&#xff01;&#039;)<\/p>\n<p>\u00a0 \u00a0 \u00a0 return<\/p>\n<p>\u00a0 \u00a0 }<\/p>\n<\/p>\n<p>\u00a0 \u00a0 \/\/ \u89e3\u5bc6\u5bc6\u94a5\u5fc5\u987b\u548c\u52a0\u5bc6\u5bc6\u94a5\u4e00\u81f4<\/p>\n<p>\u00a0 \u00a0 const secretKey &#061; &#039;1234567890123456&#039;<\/p>\n<\/p>\n<p>\u00a0 \u00a0 try {<\/p>\n<p>\u00a0 \u00a0 \u00a0 \/\/ \u8c03\u7528decryptAES\u65b9\u6cd5\u89e3\u5bc6<\/p>\n<p>\u00a0 \u00a0 \u00a0 decryptedText.value &#061; decryptAES(ciphertext.value, secretKey)<\/p>\n<p>\u00a0 \u00a0 } catch (error) {<\/p>\n<p>\u00a0 \u00a0 \u00a0 alert(&#039;\u89e3\u5bc6\u5931\u8d25&#xff08;\u5bc6\u94a5\u9519\u8bef\u6216\u5bc6\u6587\u65e0\u6548&#xff09;&#xff1a;&#039; &#043; error.message)<\/p>\n<p>\u00a0 \u00a0 \u00a0 console.error(&#039;\u89e3\u5bc6\u9519\u8bef&#xff1a;&#039;, error)<\/p>\n<p>\u00a0 \u00a0 }<\/p>\n<p>\u00a0 }<\/p>\n<p>&lt;\/script&gt;<\/p>\n<\/p>\n<p>&lt;style scoped&gt;<\/p>\n<p>\u00a0 .read-the-docs {<\/p>\n<p>\u00a0 \u00a0 color: #888;<\/p>\n<p>\u00a0 }<\/p>\n<p>\u00a0 \/* \u7b80\u5355\u7f8e\u5316\u6837\u5f0f&#xff0c;\u53ef\u9009 *\/<\/p>\n<p>\u00a0 div {<\/p>\n<p>\u00a0 \u00a0 padding: 20px;<\/p>\n<p>\u00a0 }<\/p>\n<p>\u00a0 input {<\/p>\n<p>\u00a0 \u00a0 padding: 8px;<\/p>\n<p>\u00a0 \u00a0 width: 300px;<\/p>\n<p>\u00a0 \u00a0 margin-right: 10px;<\/p>\n<p>\u00a0 }<\/p>\n<p>\u00a0 button {<\/p>\n<p>\u00a0 \u00a0 padding: 8px 16px;<\/p>\n<p>\u00a0 \u00a0 margin: 0 5px;<\/p>\n<p>\u00a0 \u00a0 cursor: pointer;<\/p>\n<p>\u00a0 \u00a0 background: #42b983;<\/p>\n<p>\u00a0 \u00a0 color: white;<\/p>\n<p>\u00a0 \u00a0 border: none;<\/p>\n<p>\u00a0 \u00a0 border-radius: 4px;<\/p>\n<p>\u00a0 }<\/p>\n<p>\u00a0 button:hover {<\/p>\n<p>\u00a0 \u00a0 background: #359469;<\/p>\n<p>\u00a0 }<\/p>\n<p>\u00a0 p {<\/p>\n<p>\u00a0 \u00a0 margin: 10px 0;<\/p>\n<p>\u00a0 \u00a0 color: #333;<\/p>\n<p>\u00a0 }<\/p>\n<p>&lt;\/style&gt;<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 CryptoJS \u5e93\u4e2d&#xff0c;Base64\u3001MD5 \u548c AES \u662f\u4e09\u79cd\u4e0d\u540c\u6027\u8d28\u7684\u7f16\u7801\u6216\u52a0\u5bc6\u65b9\u6cd5&#xff0c;\u5b83\u4eec\u5728\u539f\u7406\u3001\u7528\u9014\u548c\u5b89\u5168\u6027\u4e0a\u6709\u672c\u8d28\u533a\u522b\u7279\u6027\u00a0Base64\u00a0\u00a0\u4e0d\u5b89\u5168&#xff08;\u4ec5\u7f16\u7801&#xff09;\u5e38\u7528\u4e8e\u6570\u636e\u683c\u5f0f\u8f6c\u6362&#xff0c;\u8f93\u51fa\u5f62\u5f0f\u662f\u6587\u672c\u5b57\u7b26\u4e32MD5\u00a0\u4e0d\u5b89\u5168&#xff08;\u54c8\u5e0c&#xff09; \u5e38\u7528\u4e8e\u5b8c\u6574\u6027\u6821\u9a8c\u3001\u65e7\u5bc6\u7801\u5b58\u50a8&#xff0c;\u8f93\u51fa\u5f62\u5f0f\u662f32\u4f4d\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32AES\u00a0\u5b89\u5168&#xff08;\u5bf9\u79f0\u52a0\u5bc6&#xff09;\u5e38\u7528\u4e8e\u4fdd\u5bc6\u6570\u636e\u4f20\u8f93\u4e0e\u5b58\u50a8<\/p>\n","protected":false},"author":2,"featured_media":72658,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[187,625,87],"topic":[],"class_list":["post-72659","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-javascript","tag-vue-js","tag-87"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>vue3\u4e2d\u4f7f\u7528crypto-js\u52a0\u5bc6\/\u89e3\u5bc6&amp;&amp;\u5c01\u88c5\u52a0\u5bc6\u5de5\u5177 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/72659.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"vue3\u4e2d\u4f7f\u7528crypto-js\u52a0\u5bc6\/\u89e3\u5bc6&amp;&amp;\u5c01\u88c5\u52a0\u5bc6\u5de5\u5177 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5728 CryptoJS \u5e93\u4e2d&#xff0c;Base64\u3001MD5 \u548c AES \u662f\u4e09\u79cd\u4e0d\u540c\u6027\u8d28\u7684\u7f16\u7801\u6216\u52a0\u5bc6\u65b9\u6cd5&#xff0c;\u5b83\u4eec\u5728\u539f\u7406\u3001\u7528\u9014\u548c\u5b89\u5168\u6027\u4e0a\u6709\u672c\u8d28\u533a\u522b\u7279\u6027\u00a0Base64\u00a0\u00a0\u4e0d\u5b89\u5168&#xff08;\u4ec5\u7f16\u7801&#xff09;\u5e38\u7528\u4e8e\u6570\u636e\u683c\u5f0f\u8f6c\u6362&#xff0c;\u8f93\u51fa\u5f62\u5f0f\u662f\u6587\u672c\u5b57\u7b26\u4e32MD5\u00a0\u4e0d\u5b89\u5168&#xff08;\u54c8\u5e0c&#xff09; \u5e38\u7528\u4e8e\u5b8c\u6574\u6027\u6821\u9a8c\u3001\u65e7\u5bc6\u7801\u5b58\u50a8&#xff0c;\u8f93\u51fa\u5f62\u5f0f\u662f32\u4f4d\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32AES\u00a0\u5b89\u5168&#xff08;\u5bf9\u79f0\u52a0\u5bc6&#xff09;\u5e38\u7528\u4e8e\u4fdd\u5bc6\u6570\u636e\u4f20\u8f93\u4e0e\u5b58\u50a8\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/72659.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-06T02:49:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260206024943-698556c7b24e1.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/72659.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/72659.html\",\"name\":\"vue3\u4e2d\u4f7f\u7528crypto-js\u52a0\u5bc6\/\u89e3\u5bc6&amp;&amp;\u5c01\u88c5\u52a0\u5bc6\u5de5\u5177 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-06T02:49:44+00:00\",\"dateModified\":\"2026-02-06T02:49:44+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/72659.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/72659.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/72659.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"vue3\u4e2d\u4f7f\u7528crypto-js\u52a0\u5bc6\/\u89e3\u5bc6&amp;&amp;\u5c01\u88c5\u52a0\u5bc6\u5de5\u5177\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"vue3\u4e2d\u4f7f\u7528crypto-js\u52a0\u5bc6\/\u89e3\u5bc6&amp;&amp;\u5c01\u88c5\u52a0\u5bc6\u5de5\u5177 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/72659.html","og_locale":"zh_CN","og_type":"article","og_title":"vue3\u4e2d\u4f7f\u7528crypto-js\u52a0\u5bc6\/\u89e3\u5bc6&amp;&amp;\u5c01\u88c5\u52a0\u5bc6\u5de5\u5177 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5728 CryptoJS \u5e93\u4e2d&#xff0c;Base64\u3001MD5 \u548c AES \u662f\u4e09\u79cd\u4e0d\u540c\u6027\u8d28\u7684\u7f16\u7801\u6216\u52a0\u5bc6\u65b9\u6cd5&#xff0c;\u5b83\u4eec\u5728\u539f\u7406\u3001\u7528\u9014\u548c\u5b89\u5168\u6027\u4e0a\u6709\u672c\u8d28\u533a\u522b\u7279\u6027\u00a0Base64\u00a0\u00a0\u4e0d\u5b89\u5168&#xff08;\u4ec5\u7f16\u7801&#xff09;\u5e38\u7528\u4e8e\u6570\u636e\u683c\u5f0f\u8f6c\u6362&#xff0c;\u8f93\u51fa\u5f62\u5f0f\u662f\u6587\u672c\u5b57\u7b26\u4e32MD5\u00a0\u4e0d\u5b89\u5168&#xff08;\u54c8\u5e0c&#xff09; \u5e38\u7528\u4e8e\u5b8c\u6574\u6027\u6821\u9a8c\u3001\u65e7\u5bc6\u7801\u5b58\u50a8&#xff0c;\u8f93\u51fa\u5f62\u5f0f\u662f32\u4f4d\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32AES\u00a0\u5b89\u5168&#xff08;\u5bf9\u79f0\u52a0\u5bc6&#xff09;\u5e38\u7528\u4e8e\u4fdd\u5bc6\u6570\u636e\u4f20\u8f93\u4e0e\u5b58\u50a8","og_url":"https:\/\/www.wsisp.com\/helps\/72659.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-06T02:49:44+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260206024943-698556c7b24e1.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/72659.html","url":"https:\/\/www.wsisp.com\/helps\/72659.html","name":"vue3\u4e2d\u4f7f\u7528crypto-js\u52a0\u5bc6\/\u89e3\u5bc6&amp;&amp;\u5c01\u88c5\u52a0\u5bc6\u5de5\u5177 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-06T02:49:44+00:00","dateModified":"2026-02-06T02:49:44+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/72659.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/72659.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/72659.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"vue3\u4e2d\u4f7f\u7528crypto-js\u52a0\u5bc6\/\u89e3\u5bc6&amp;&amp;\u5c01\u88c5\u52a0\u5bc6\u5de5\u5177"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/72659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=72659"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/72659\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/72658"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=72659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=72659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=72659"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=72659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}