var CryptoJS = require("crypto-js"); var key = "QWER123456"; var iv = "156465465"; function encrypt(text) { return CryptoJS.AES.encrypt(text, CryptoJS.enc.Utf8.parse(key), { iv: CryptoJS.enc.Utf8.parse(iv), mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }) } function decrypt(text) { var result = CryptoJS.AES.decrypt(text, CryptoJS.enc.Utf8.parse(key), { iv: CryptoJS.enc.Utf8.parse(iv), mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }) return result.toString(CryptoJS.enc.Utf8) } var text = ”aes jiami"; var encoded=encrypt(text) console.log(encoded.toString()); console.log(decrypt(encoded))"
padding的常见三种模式:
NoPadding
• PKCS7Padding
• ZeroPadding
mode:CBC, EBC