Skip to main content

数据解密

请求API,返回的response报文,其中headers包含lj_encrypt字段的,需要进行数据解密

获取秘钥(BizConfig/read/apiAesSecretKey)

  • 不需要headers中传token

  • 输入:无

  • 输出:

名称字段类型可选说明
编码codestringN
创建日期createtimedateN
名称namestringN
说明remarkstringY
类型typenumberN
秘钥valuestringN使用的秘钥

数据解密

安装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); // 解密后可用的数据