dream-common 1.1.42 → 1.1.45

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.
@@ -2,7 +2,8 @@
2
2
 
3
3
  import {
4
4
  sm2,
5
- sm4
5
+ sm4,
6
+ sm3
6
7
  } from 'sm-crypto';
7
8
  import {base64ToHex, hexToBase64} from './Base64Utils.js';
8
9
  import {md5} from './md5.js';
@@ -49,9 +50,12 @@ export function encryptSecureData(request = {}, privateKey, useBase64 = true) {
49
50
 
50
51
  const signValue = useBase64 ? hexToBase64(signValueStr) : signValueStr;
51
52
  // 3. 生成 SM4 密钥和 IV(通过 MD5)
52
- const keyHex = md5_32(signValue); // 32 hex → 16 bytes
53
- const ivHex = md5_32(signSource); // 32 hex → 16 bytes
54
-
53
+ const hashData = sm3(signValue) // 杂凑
54
+ const keyHex = md5_32(signValue + hashData); // 32 hex → 16 bytes
55
+ const ivHex = md5_32(signSource + keyHex + hashData); // 32 hex → 16 bytes
56
+ console.log("hashData: " + hashData);
57
+ console.log("keyHex: " + keyHex);
58
+ console.log("ivHex: " + ivHex);
55
59
  // 4. 序列化业务数据
56
60
  const dataJson = typeof request.data === 'string' ? request.data : JSON.stringify(request.data);
57
61
 
@@ -86,7 +90,7 @@ export function encryptSecureData(request = {}, privateKey, useBase64 = true) {
86
90
  * @returns {boolean}
87
91
  */
88
92
  export function verifySecureSign(request, publicKey, useBase64 = true) {
89
- const signSource = objectToSignString(request, 'encData', 'signData', 'data');
93
+ const signSource = objectToSignString(request, 'signData', 'data');
90
94
  const signatureHex = useBase64 ? base64ToHex(request.signData) : request.signData;
91
95
  return sm2.doVerifySignature(signSource, signatureHex, publicKey, {
92
96
  der: true
@@ -104,9 +108,12 @@ export function verifySecureSign(request, publicKey, useBase64 = true) {
104
108
  export function decryptSecureData(request, privateKey, useBase64 = true) {
105
109
  // 1. 重算签名原文(用于生成 key/iv)
106
110
  const signSource = objectToSignString(request, 'encData', 'signData', 'data');
107
- const lvHax = md5_32(signSource);
108
- const keyHax = md5_32(request.signData);
109
-
111
+ const hashData = sm3(signValue) // 杂凑
112
+ const keyHex = md5_32(signValue + hashData); // 32 hex → 16 bytes
113
+ const ivHex = md5_32(signSource + keyHex + hashData); // 32 hex → 16 bytes
114
+ console.log("sm3: " + hashData);
115
+ console.log("keyHex: " + keyHex);
116
+ console.log("ivHex: " + ivHex);
110
117
  // 3. 处理 encData(base64 → hex)
111
118
 
112
119
  const encDataHex = useBase64 ? base64ToHex(request.encData) : request.encData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dream-common",
3
- "version": "1.1.42",
3
+ "version": "1.1.45",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {