dream-common 1.1.48 → 1.1.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -48,8 +48,8 @@ export function encryptSecureData(request = {}, privateKey, useBase64 = true) {
|
|
|
48
48
|
|
|
49
49
|
// 3. 生成 SM4 密钥和 IV(通过 MD5)
|
|
50
50
|
const hashData = sm3(queryStr) // 杂凑
|
|
51
|
-
const keyHex = md5_32(
|
|
52
|
-
const ivHex = md5_32(
|
|
51
|
+
const keyHex = md5_32(hashData); // 32 hex → 16 bytes
|
|
52
|
+
const ivHex = md5_32(keyHex + hashData); // 32 hex → 16 bytes
|
|
53
53
|
// 5. SM4 加密(CBC + PKCS#7)
|
|
54
54
|
const encDataHex = sm4.encrypt(dataJson, keyHex, {
|
|
55
55
|
iv: ivHex,
|
|
@@ -109,8 +109,8 @@ export function decryptSecureData(request, privateKey, useBase64 = true) {
|
|
|
109
109
|
// 1. 重算签名原文(用于生成 key/iv)
|
|
110
110
|
const queryStr = objectToSignString(request, 'encData', 'signData', 'data');
|
|
111
111
|
const hashData = sm3(queryStr) // 杂凑
|
|
112
|
-
const keyHex = md5_32(
|
|
113
|
-
const ivHex = md5_32(
|
|
112
|
+
const keyHex = md5_32(hashData); // 32 hex → 16 bytes
|
|
113
|
+
const ivHex = md5_32(keyHex + hashData); // 32 hex → 16 bytes
|
|
114
114
|
// 3. 处理 encData(base64 → hex)
|
|
115
115
|
const encDataHex = useBase64 ? base64ToHex(request.encData) : request.encData;
|
|
116
116
|
// 4. SM4 解密
|