前端使用3DES加密
作者:互联网
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(); };
标签:3DES,加密,decryptedStr,前端,iv,mode,KEY,const,CryptoJS 来源: https://www.cnblogs.com/newBugs/p/16521015.html