沐若清辰
人生如茶,浓也好,淡也好,各有味道

https://www.jianshu.com/p/4c236d83ea04

https://blog.csdn.net/FightBirds/article/details/90648657

https://www.cnblogs.com/ylz8401/p/7279794.html

 

//例如:
//1.安装  crypto-js;
 var CryptoJS = require("crypto-js");
//3.加入方法:
 //aes加密
      encrypt(context) {
        var key = CryptoJS.enc.Utf8.parse("Manager-Org-DIFF");
        var iv = CryptoJS.enc.Utf8.parse("A-Manage-Org-DGF");
        var encrypted = '';
        if (typeof(context) == 'string') {

        }else if(typeof(context) == 'object'){
          context = JSON.stringify(context);
        }
        var srcs = CryptoJS.enc.Utf8.parse(context);
        encrypted = CryptoJS.AES.encrypt(srcs, key, {
            iv: iv,
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7
        });
        return encrypted.toString();
      },
       // aes解密
      decrypt(context) {
        console.log(context)
        var key = CryptoJS.enc.Utf8.parse("Manager-Org-DIFF");
        var iv = CryptoJS.enc.Utf8.parse("A-Manage-Org-DGF");
        var decrypt = CryptoJS.AES.decrypt(context, key, {
            iv: iv,
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7
        });
        var decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
        return decryptedStr.toString();
      },

     // 4.将需要的数据进行加密则:
      deptId:this.encrypt(this.nodeItem.deptId),   //将部门ID进行加密

    //5.将需要的数据进行解密:
        res.data.infoExt.idcardno = this.decrypt(res.data.infoExt.idcardno)
   

  

posted on 2020-03-11 14:04  沐若清辰  阅读(5074)  评论(0编辑  收藏  举报