js AES key32(Pkcs7/Pkcs5)位加解密
<script src="aes.js"></script>
<script src="pad-zeropadding.js"></script>
<script src="base64.js"></script>
<script>
var data = "JO0009700170";
var key = CryptoJS.enc.Utf8.parse('02ccacbd35ebd5d674839b114eba4cb4');
var iv = CryptoJS.enc.Utf8.parse('a2fe63789f3e7234');
//加密
var encrypted = CryptoJS.AES.encrypt(data,key,{iv:iv,mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7});
//var b = new base64();
var str = Base64.encode(encrypted);
document.write(encrypted+"-------------"+str);
var encryptedBase64Str = encrypted.toString();
// 输出:'RJcecVhTqCHHnlibzTypzuDvG8kjWC+ot8JuxWVdLgY='
console.log(encryptedBase64Str);
//解密
var decrypted = CryptoJS.AES.decrypt(encrypted,key,{iv:iv,mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Pkcs7});
console.log(decrypted.toString(CryptoJS.enc.Utf8)+"=================");
function returnAES() {
return encrypted
};
document.write(".................."+returnAES()+"..................");
//console.log(decrypted.toString(CryptoJS.enc.Utf8)+"=================");
</script>
参考:https://github.com/Acvrock/AES-Encryption-in-IOS-Java-JavaScript 改动