JavaScript加密,解密
1,此为AES加密后,转换为16进制编码
var encodePwd = function (data,key){ var keyHex = CryptoJS.enc.Utf8.parse(key); var encrypted1 = CryptoJS.AES.encrypt(data, keyHex, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); return CryptoJS.enc.Hex.parse(encrypted1.ciphertext.toString()); } var decodePwd = function (data,key){ var keyHex = CryptoJS.enc.Utf8.parse(key); var decrypted = CryptoJS.AES.decrypt({ ciphertext: CryptoJS.enc.Hex.parse(data) }, keyHex, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); return decrypted.toString(CryptoJS.enc.Utf8); }
2,此为AES加密后,转换base64位编码
var encodePwd = function (data,key){ var keyHex = CryptoJS.enc.Utf8.parse(key); var encrypted1 = CryptoJS.AES.encrypt(data, keyHex, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); return CryptoJS.enc.Base64.parse(encrypted1.ciphertext.toString()); } var decodePwd = function (data,key){ var keyHex = CryptoJS.enc.Utf8.parse(key); var decrypted = CryptoJS.AES.decrypt({ ciphertext: CryptoJS.enc.Base64.parse(data) }, keyHex, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); return decrypted.toString(CryptoJS.enc.Utf8); }
时间: 2024-11-10 21:49:09