首先下载大包
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高版本的资料在国内真不好找,一个坑一个坑的踩过去,希望国内社区越来越强吧