TS && JS版本 npm install --save @types/crypto-js npm install crypto-js import CryptoJS from 'crypto-js'; /** * 3DES 加密 * iv: --后端提供偏移量 * KEY: --密码 后端提供 * mode: CBC --加密方式 需要iv */ const KEY = CryptoJS.enc.Utf8.parse('E6A84673893E8C97E6D55483574F385DF8677AAB011570F2'); const iv = CryptoJS.enc.Utf8.parse('ASDFGHJK'); export const AES_Encrypt = (plaintext: any) => { let decryptedStr = CryptoJS.TripleDES.encrypt(plaintext, KEY, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7, }); return decryptedStr.ciphertext.toString(); }; /** * 3DES 解密 */ export const AES_Decrypt = (jsonStr: any) => { let decryptedStr = CryptoJS.TripleDES.decrypt(plaintext, KEY, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7, }); return decryptedStr.ciphertext.toString(); };