import CryptoJS from "crypto-js";
var data1={
name:'李雷',
age:18
}//要加密的数据
var aseKey='1234567890123456789012335475';//秘钥
var key = CryptoJS.enc.Utf8.parse(aseKey);//将秘钥转换成Utf8字节数组
//加密
var encrypt = CryptoJS.AES.encrypt(JSON.stringify(data1), key, {
iv: CryptoJS.enc.Utf8.parse(aseKey.substr(0,16)),
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
})
var data2=encrypt.toString();//加密后的数据
//解密
var decrypt = CryptoJS.AES.decrypt(data2, key, {
iv: CryptoJS.enc.Utf8.parse(aseKey.substr(0,16)),
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
var data3=JSON.parse(decrypt.toString(CryptoJS.enc.Utf8));//解密后的数据
// console.log(data2);
var a='jfnktmmpfidptdjk'
var b='2022-11-03WDEj7f'
function parse(utf8Str) {
return CryptoJS.enc.Utf8.parse(utf8Str);
}
function decode(wordArray){
return CryptoJS.enc.Utf8.stringify(wordArray)
}