dream-common 1.1.18 → 1.1.19

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.
package/index.js CHANGED
@@ -15,5 +15,6 @@ export default {
15
15
  ...require('./lib/authorization'),
16
16
  ...require('./lib/json'),
17
17
  ...require('./lib/CryptoJS/Base58'),
18
+ ...require('./lib/CryptoJS/HttpData'),
18
19
  ...require('./lib/CryptoJS/AesUtils')
19
20
  }
@@ -0,0 +1,90 @@
1
+ import {md5_48,md5_16} from "./md5";
2
+ import {aesEncrypt,aesDecrypt} from "./AesUtils";
3
+ import {decodeBase58,encodeBase58} from "./Base58";
4
+ export const reqEncrypt = (orgId, content) => {
5
+ return reqDataEncrypt(orgId,"1.0.0","MD5","AES", content);
6
+ }
7
+ export const respDecrypt = (orgId, content) => {
8
+ return respDataDecrypt(orgId,"1.0.0","MD5","AES", content);
9
+ }
10
+ export const respDataDecrypt = (obj) => {
11
+ try {
12
+ if (typeof content === 'object' || JSON.stringify(content) !== "{}") {
13
+ if (obj.encType === "NONE") {
14
+ return obj.data;
15
+ } else {
16
+ let signStr = decodeBase58(obj.signData);
17
+ let encData = encodeBase58(aesDecrypt(md5_16(signStr), obj.encData));
18
+ let obj = {};
19
+ let pairs = encData.split('&');
20
+ for (let i = 0; i < pairs.length; i++) {
21
+ let pair = pairs[i].split('=');
22
+ let key = pair[0];
23
+ let value = pair[1] || '';
24
+ if (key.substring(key.length - 2) === '[]') {
25
+ key = key.substring(0, key.length - 2);
26
+ if (!obj[key]) {
27
+ obj[key] = [];
28
+ }
29
+ obj[key].push(value);
30
+ } else {
31
+ obj[key] = value;
32
+ }
33
+ }
34
+ return obj.data;
35
+ }
36
+ } else {
37
+ return obj;
38
+ }
39
+ } catch (e) {
40
+ return {};
41
+ }
42
+
43
+
44
+ }
45
+
46
+
47
+ export const reqDataEncrypt = (orgId,version,signType,encType, content) => {
48
+ let obj = {
49
+ "orgId": orgId,
50
+ "version": version,
51
+ "signType": signType,
52
+ "encType": encType,
53
+ };
54
+ try {
55
+ // 如果obj不是一个对象或者是null,直接返回它
56
+ if (typeof content !== 'object' || content === null || JSON.stringify(content) === "{}") {
57
+ obj.data = "";
58
+ } else {
59
+ obj.data = JSON.stringify(data);
60
+ }
61
+ // 提取对象的键到一个数组中
62
+ let keys = Object.keys(obj);
63
+ // 按照第一个字符的ASCII码递增排序
64
+ keys.sort((a, b) => a.charCodeAt(0) - b.charCodeAt(0));
65
+ // 创建一个新的对象,用于存储按排序后键值的结果
66
+ let sortedObj = {};
67
+ keys.forEach(key => {
68
+ sortedObj[key] = obj[key];
69
+ });
70
+ // 构建待签名字符串
71
+ let signStringArray = [];
72
+ for (let key in sortedObj) {
73
+ signStringArray.push(`${key}=${sortedObj[key]}`);
74
+ }
75
+ let str = signStringArray.join('&');
76
+ let sign = md5_48(str);
77
+ // 删除键为 "content" 的属性
78
+ delete obj.data;
79
+ obj.encData = encodeBase58(aesEncrypt(md5_16(sign), str));
80
+ obj.signData = encodeBase58(sign);
81
+ obj.timestamp = new Date().getTime();
82
+ return obj;
83
+ } catch (e) {
84
+ obj.signType ="NONE";
85
+ obj.encType ="NONE";
86
+ obj.data = content;
87
+ obj.timestamp = new Date().getTime();
88
+ return obj;
89
+ }
90
+ }
@@ -11,7 +11,7 @@ export const md5 = content => {
11
11
  }
12
12
  export const md5_16 = content => {
13
13
  let str = md5(content);
14
- return str.substring(9, 24);
14
+ return str.substring(8, 24);
15
15
  }
16
16
  export const md5_48 = content => {
17
17
  let salt = uuid(false,16,16);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dream-common",
3
- "version": "1.1.18",
3
+ "version": "1.1.19",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {