var key = CryptoJS.enc.Utf8.parse(“你的key”); //加密 function encrypt(word) { var srcs = CryptoJS.enc.Utf8.parse(word); var encrypt = CryptoJS.AES.encrypt(srcs,key,{ mode:CryptoJS.mode.ECB, padding:CryptoJS.pad.Pkcs7 }); return encrypt.toString(); } //解密 function decrypt(word) { var decrypt = CryptoJS.AES.decrypt(word,key,{ mode:CryptoJS.mode.ECB, padding:CryptoJS.pad.Pkcs7 }); return CryptoJS.enc.Utf8.stringify(decrypt).toString(); }
引入js文件
使用:
encrypt('1563011')