前端angular使用crypto-js進行加密


首先下載大包

npm install crypto-js

然后下載ts版本的包

npm install --save @types/crypto-js

接着在頭部導入crypto-js模塊

import { AES, mode, pad, enc } from 'crypto-js';

加密方法

//aes加密
  encryptByEnAES(data: string): string {
    let Key = "123456";
    let tmpAES = AES.encrypt(data, Key, {
      mode: mode.CBC,
      padding: pad.Pkcs7
    });
    return tmpAES.toString();
  }

解密方法

encryptByDeAES(data: string): string {
    let Key = "123456";
    let tmpDeAES = AES.decrypt(data, Key, {
      mode: mode.CBC,
      padding: pad.Pkcs7
    });
    return tmpDeAES.toString(enc.Utf8);
  }

 

結束語:angular高版本的資料在國內真不好找,一個坑一個坑的踩過去,希望國內社區越來越強吧


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM