数据解密
请求API,返回的response报文,其中headers包含lj_encrypt字段的,需要进行数据解密
获取秘钥(BizConfig/read/apiAesSecretKey)
不需要headers中传token
输入:无
输出:
名称 | 字段 | 类型 | 可选 | 说明 |
---|---|---|---|---|
编码 | code | string | N | |
创建日期 | createtime | date | N | |
名称 | name | string | N | |
说明 | remark | string | Y | |
类型 | type | number | N | |
秘钥 | value | string | N | 使用的秘钥 |
数据解密
安装crypto-js
npm install crypto-js
使用crypto-js解密
import CryptoJS from "crypto-js"
function decrypt(cipherText, key) {
// Base64解码密钥和密文
var decodedKey = CryptoJS.enc.Base64.parse(key);
var decodedCipherText = CryptoJS.enc.Base64.parse(cipherText);
// 使用解码后的密钥进行解密
var decrypted = CryptoJS.AES.decrypt({ ciphertext: decodedCipherText }, decodedKey, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
// 将解密结果转换为UTF-8字符串
return decrypted.toString(CryptoJS.enc.Utf8);
}
var responseData = 接口返回的加密数据;
var secretKey = 通过接口BizConfig/read/apiAesSecretKey获取的秘钥
var data = decrypt(responseData,secretKey); // 解密后可用的数据