使用的加密包是 crypto-js
import CryptoJS from 'crypto-js';
加密模式是 ECB,填充方式 Pkcs7, 输出方式 Base64,字符集 utf8
// 加密 desEncrypt(str, desSecretKey) { let APIFMS; try { let keyHex_encrypt = CryptoJS.enc.Utf8.parse(desSecretKey); let encrypted = CryptoJS.DES.encrypt(str, keyHex_encrypt, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); APIFMS = CryptoJS.enc.Base64.stringify(encrypted.ciphertext); } catch (err) { console.log('des 加密 -------------------------'); console.log(err); } return APIFMS; } // 解密 desDecrypt(str, desSecretKey) { let result_value; try { let keyHex_decrypt = CryptoJS.enc.Utf8.parse(desSecretKey); let decrypted = CryptoJS.DES.decrypt({ ciphertext: CryptoJS.enc.Base64.parse(str) }, keyHex_decrypt, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); result_value = decrypted.toString(CryptoJS.enc.Utf8); } catch (err) { console.log('des 解密 ------------------------- '); console.log(err); console.log("解密前数据:" + str); } return result_value; }