我使用Angular cryptoJS
和AES
来加密和解密敏感数据并存储在本地存储中。我使用硬编码'KEY'进行加密和解密。 But how do i use dynamic key instead of hard coded key?
setStorageData(storageInfoObj: any){
let dataobj = {"institutionid":"159198","userimage":"","firstname":""};
let d = CryptoJS.AES.encrypt(JSON.stringify(dataobj), "123456").toString();
this.storage.set('deviceinfo', d);
}
getStorageData() {
return this.storage.get('deviceinfo').then((deviceObj:any) => {
if (deviceObj) {
try {
let decrdata = CryptoJS.AES.decrypt(deviceObj, "123456");
return this.encryptDataObj = JSON.parse(decrdata.toString(CryptoJS.enc.Utf8));
} catch (err) {
}
}
}
);
}