试图使用加密-js封装和解密json数据。但不起作用。如何找到解决之道。如果有人知道,请帮忙找出解决办法。
演示:https://stackblitz.com/edit/angular-ivy-nwhkgz?file=src%2Fapp%2Fapp.component.ts
storageData=
[
{
"customerInfo": {
"Micheal": 1,
"Milson": 2
},
"mycart": {
"Ol1": 1,
"Ol3": 1
},
"cartItemsList": [
{
"pid": "Ol1",
"name": "Avacota",
"qty": 1
},
{
"pid": "Ol3",
"name": "Kaliflower",
"qty": 1
}
],
"cartTotal": 2
}
];
ngOnInit(){
//Encrypt Info
this.encryptInfo = encodeURIComponent(CryptoJS.AES.encrypt(this.storageData, 'secret key 123').toString());
console.log("encryptInfo");
console.log(this.encryptInfo);
//Decrypt Info
var deData= CryptoJS.AES.decrypt(this.encryptInfo, 'secret key 123');
this.decryptedInfo = decodeURIComponent(deData.toString(CryptoJS.enc.Utf8));
console.log("decryptedInfo");
console.log(this.decryptedInfo);
}发布于 2020-09-02 09:57:14
首先:我不建议你在没有咨询精通密码学和网络安全的人之前亲自为生产使用做这件事。
有两个错误阻碍了密码部分的工作:
以下是固定的stackblitz:https://stackblitz.com/edit/angular-ivy-h6zlcv?devtoolsheight=33&file=src/app/app.component.ts
https://stackoverflow.com/questions/63702556
复制相似问题