使用动态密钥使用AES加密加密敏感数据

时间:2017-12-21 13:20:19

标签: javascript angularjs encryption aes

我使用Angular cryptoJSAES来加密和解密敏感数据并存储在本地存储中。我使用硬编码'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) {

              }
            }

          }
        );
       }

0 个答案:

没有答案