1.首先npm i crypto-js
2.找到node_modules下的crypto-js文件夹
3.在crypto-js文件下找到crypto-js.js,将它复制到你存放工具类js的文件夹下,例如我放到了utils文件夹下
4.使用
var CryptoJS = require('./crypto-js/crypto-js'); 写一个加密函数并导出 export const encryptAES = (word, keyStr) => { var key = CryptoJS.enc.Utf8.parse(keyStr); var srcs = CryptoJS.enc.Utf8.parse(word); var encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); return encrypted.toString(); } 具体的AES mode等参数自己调整就可以了 标签:AES,微信,crypto,js,mode,var,CryptoJS From: https://www.cnblogs.com/idontcare/p/18199622