@tmsfe/tms-core 0.0.118 → 0.0.120
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/package.json +1 -1
- package/src/md5.js +365 -177
- package/src/request.js +2 -2
package/package.json
CHANGED
package/src/md5.js
CHANGED
|
@@ -1,187 +1,375 @@
|
|
|
1
|
-
|
|
2
|
-
* @author Davis.Lu <davislu@tencent.com>
|
|
3
|
-
* @desc: 基于md5算法对源字符串进行hash,生成hash字符串
|
|
4
|
-
**/
|
|
5
|
-
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
6
2
|
/**
|
|
7
3
|
* @public
|
|
8
4
|
* @description 基于md5算法对源字符串进行hash,生成hash字符串
|
|
9
5
|
* @param {String} str 源字符串
|
|
10
6
|
* @returns {String} 源字符串的md5 hash值
|
|
7
|
+
* MIT https://github.com/blueimp/JavaScript-MD5
|
|
11
8
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Add integers, wrapping at 2^32.
|
|
11
|
+
* This uses 16-bit operations internally to work around bugs in interpreters.
|
|
12
|
+
*
|
|
13
|
+
* @param {number} x First integer
|
|
14
|
+
* @param {number} y Second integer
|
|
15
|
+
* @returns {number} Sum
|
|
16
|
+
*/
|
|
17
|
+
function safeAdd(x, y) {
|
|
18
|
+
const lsw = (x & 0xffff) + (y & 0xffff);
|
|
19
|
+
const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
|
20
|
+
return (msw << 16) | (lsw & 0xffff);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Bitwise rotate a 32-bit number to the left.
|
|
25
|
+
*
|
|
26
|
+
* @param {number} num 32-bit number
|
|
27
|
+
* @param {number} cnt Rotation count
|
|
28
|
+
* @returns {number} Rotated number
|
|
29
|
+
*/
|
|
30
|
+
function bitRotateLeft(num, cnt) {
|
|
31
|
+
return (num << cnt) | (num >>> (32 - cnt));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Basic operation the algorithm uses.
|
|
36
|
+
*
|
|
37
|
+
* @param {number} q q
|
|
38
|
+
* @param {number} a a
|
|
39
|
+
* @param {number} b b
|
|
40
|
+
* @param {number} x x
|
|
41
|
+
* @param {number} s s
|
|
42
|
+
* @param {number} t t
|
|
43
|
+
* @returns {number} Result
|
|
44
|
+
*/
|
|
45
|
+
function md5cmn(q, a, b, x, s, t) {
|
|
46
|
+
return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Basic operation the algorithm uses.
|
|
50
|
+
*
|
|
51
|
+
* @param {number} a a
|
|
52
|
+
* @param {number} b b
|
|
53
|
+
* @param {number} c c
|
|
54
|
+
* @param {number} d d
|
|
55
|
+
* @param {number} x x
|
|
56
|
+
* @param {number} s s
|
|
57
|
+
* @param {number} t t
|
|
58
|
+
* @returns {number} Result
|
|
59
|
+
*/
|
|
60
|
+
function md5ff(a, b, c, d, x, s, t) {
|
|
61
|
+
return md5cmn((b & c) | (~b & d), a, b, x, s, t);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Basic operation the algorithm uses.
|
|
65
|
+
*
|
|
66
|
+
* @param {number} a a
|
|
67
|
+
* @param {number} b b
|
|
68
|
+
* @param {number} c c
|
|
69
|
+
* @param {number} d d
|
|
70
|
+
* @param {number} x x
|
|
71
|
+
* @param {number} s s
|
|
72
|
+
* @param {number} t t
|
|
73
|
+
* @returns {number} Result
|
|
74
|
+
*/
|
|
75
|
+
function md5gg(a, b, c, d, x, s, t) {
|
|
76
|
+
return md5cmn((b & d) | (c & ~d), a, b, x, s, t);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Basic operation the algorithm uses.
|
|
80
|
+
*
|
|
81
|
+
* @param {number} a a
|
|
82
|
+
* @param {number} b b
|
|
83
|
+
* @param {number} c c
|
|
84
|
+
* @param {number} d d
|
|
85
|
+
* @param {number} x x
|
|
86
|
+
* @param {number} s s
|
|
87
|
+
* @param {number} t t
|
|
88
|
+
* @returns {number} Result
|
|
89
|
+
*/
|
|
90
|
+
function md5hh(a, b, c, d, x, s, t) {
|
|
91
|
+
return md5cmn(b ^ c ^ d, a, b, x, s, t);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Basic operation the algorithm uses.
|
|
95
|
+
*
|
|
96
|
+
* @param {number} a a
|
|
97
|
+
* @param {number} b b
|
|
98
|
+
* @param {number} c c
|
|
99
|
+
* @param {number} d d
|
|
100
|
+
* @param {number} x x
|
|
101
|
+
* @param {number} s s
|
|
102
|
+
* @param {number} t t
|
|
103
|
+
* @returns {number} Result
|
|
104
|
+
*/
|
|
105
|
+
function md5ii(a, b, c, d, x, s, t) {
|
|
106
|
+
return md5cmn(c ^ (b | ~d), a, b, x, s, t);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Calculate the MD5 of an array of little-endian words, and a bit length.
|
|
111
|
+
*
|
|
112
|
+
* @param {Array} x Array of little-endian words
|
|
113
|
+
* @param {number} len Bit length
|
|
114
|
+
* @returns {Array<number>} MD5 Array
|
|
115
|
+
*/
|
|
116
|
+
function binlMD5(x, len) {
|
|
117
|
+
/* append padding */
|
|
118
|
+
x[len >> 5] |= 0x80 << len % 32;
|
|
119
|
+
x[(((len + 64) >>> 9) << 4) + 14] = len;
|
|
120
|
+
|
|
121
|
+
let i;
|
|
122
|
+
let olda;
|
|
123
|
+
let oldb;
|
|
124
|
+
let oldc;
|
|
125
|
+
let oldd;
|
|
126
|
+
let a = 1732584193;
|
|
127
|
+
let b = -271733879;
|
|
128
|
+
let c = -1732584194;
|
|
129
|
+
let d = 271733878;
|
|
130
|
+
|
|
131
|
+
for (i = 0; i < x.length; i += 16) {
|
|
132
|
+
olda = a;
|
|
133
|
+
oldb = b;
|
|
134
|
+
oldc = c;
|
|
135
|
+
oldd = d;
|
|
136
|
+
|
|
137
|
+
a = md5ff(a, b, c, d, x[i], 7, -680876936);
|
|
138
|
+
d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
|
|
139
|
+
c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
|
|
140
|
+
b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
|
|
141
|
+
a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
|
|
142
|
+
d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
|
|
143
|
+
c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
|
|
144
|
+
b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
|
|
145
|
+
a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
|
|
146
|
+
d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
|
|
147
|
+
c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
|
|
148
|
+
b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
|
|
149
|
+
a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
|
|
150
|
+
d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
|
|
151
|
+
c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
|
|
152
|
+
b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
|
|
153
|
+
|
|
154
|
+
a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
|
|
155
|
+
d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
|
|
156
|
+
c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
|
|
157
|
+
b = md5gg(b, c, d, a, x[i], 20, -373897302);
|
|
158
|
+
a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
|
|
159
|
+
d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
|
|
160
|
+
c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
|
|
161
|
+
b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
|
|
162
|
+
a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
|
|
163
|
+
d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
|
|
164
|
+
c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
|
|
165
|
+
b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
|
|
166
|
+
a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
|
|
167
|
+
d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
|
|
168
|
+
c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
|
|
169
|
+
b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
|
|
170
|
+
|
|
171
|
+
a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
|
|
172
|
+
d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
|
|
173
|
+
c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
|
|
174
|
+
b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
|
|
175
|
+
a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
|
|
176
|
+
d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
|
|
177
|
+
c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
|
|
178
|
+
b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
|
|
179
|
+
a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
|
|
180
|
+
d = md5hh(d, a, b, c, x[i], 11, -358537222);
|
|
181
|
+
c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
|
|
182
|
+
b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
|
|
183
|
+
a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
|
|
184
|
+
d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
|
|
185
|
+
c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
|
|
186
|
+
b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
|
|
187
|
+
|
|
188
|
+
a = md5ii(a, b, c, d, x[i], 6, -198630844);
|
|
189
|
+
d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
|
|
190
|
+
c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
|
|
191
|
+
b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
|
|
192
|
+
a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
|
|
193
|
+
d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
|
|
194
|
+
c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
|
|
195
|
+
b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
|
|
196
|
+
a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
|
|
197
|
+
d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
|
|
198
|
+
c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
|
|
199
|
+
b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
|
|
200
|
+
a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
|
|
201
|
+
d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
|
|
202
|
+
c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
|
|
203
|
+
b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
|
|
204
|
+
|
|
205
|
+
a = safeAdd(a, olda);
|
|
206
|
+
b = safeAdd(b, oldb);
|
|
207
|
+
c = safeAdd(c, oldc);
|
|
208
|
+
d = safeAdd(d, oldd);
|
|
209
|
+
}
|
|
210
|
+
return [a, b, c, d];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Convert an array of little-endian words to a string
|
|
215
|
+
*
|
|
216
|
+
* @param {Array<number>} input MD5 Array
|
|
217
|
+
* @returns {string} MD5 string
|
|
218
|
+
*/
|
|
219
|
+
function binl2rstr(input) {
|
|
220
|
+
let i;
|
|
221
|
+
let output = '';
|
|
222
|
+
const length32 = input.length * 32;
|
|
223
|
+
for (i = 0; i < length32; i += 8) {
|
|
224
|
+
output += String.fromCharCode((input[i >> 5] >>> i % 32) & 0xff);
|
|
225
|
+
}
|
|
226
|
+
return output;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Convert a raw string to an array of little-endian words
|
|
231
|
+
* Characters >255 have their high-byte silently ignored.
|
|
232
|
+
*
|
|
233
|
+
* @param {string} input Raw input string
|
|
234
|
+
* @returns {Array<number>} Array of little-endian words
|
|
235
|
+
*/
|
|
236
|
+
function rstr2binl(input) {
|
|
237
|
+
let i;
|
|
238
|
+
const output = [];
|
|
239
|
+
output[(input.length >> 2) - 1] = undefined;
|
|
240
|
+
for (i = 0; i < output.length; i += 1) {
|
|
241
|
+
output[i] = 0;
|
|
242
|
+
}
|
|
243
|
+
const length8 = input.length * 8;
|
|
244
|
+
for (i = 0; i < length8; i += 8) {
|
|
245
|
+
output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << i % 32;
|
|
246
|
+
}
|
|
247
|
+
return output;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Calculate the MD5 of a raw string
|
|
252
|
+
*
|
|
253
|
+
* @param {string} s Input string
|
|
254
|
+
* @returns {string} Raw MD5 string
|
|
255
|
+
*/
|
|
256
|
+
function rstrMD5(s) {
|
|
257
|
+
return binl2rstr(binlMD5(rstr2binl(s), s.length * 8));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Calculates the HMAC-MD5 of a key and some data (raw strings)
|
|
262
|
+
*
|
|
263
|
+
* @param {string} key HMAC key
|
|
264
|
+
* @param {string} data Raw input string
|
|
265
|
+
* @returns {string} Raw MD5 string
|
|
266
|
+
*/
|
|
267
|
+
function rstrHMACMD5(key, data) {
|
|
268
|
+
let i;
|
|
269
|
+
let bkey = rstr2binl(key);
|
|
270
|
+
const ipad = [];
|
|
271
|
+
const opad = [];
|
|
272
|
+
ipad[15] = undefined;
|
|
273
|
+
opad[15] = undefined;
|
|
274
|
+
if (bkey.length > 16) {
|
|
275
|
+
bkey = binlMD5(bkey, key.length * 8);
|
|
276
|
+
}
|
|
277
|
+
for (i = 0; i < 16; i += 1) {
|
|
278
|
+
ipad[i] = bkey[i] ^ 0x36363636;
|
|
279
|
+
opad[i] = bkey[i] ^ 0x5c5c5c5c;
|
|
280
|
+
}
|
|
281
|
+
const hash = binlMD5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
|
|
282
|
+
return binl2rstr(binlMD5(opad.concat(hash), 512 + 128));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Convert a raw string to a hex string
|
|
287
|
+
*
|
|
288
|
+
* @param {string} input Raw input string
|
|
289
|
+
* @returns {string} Hex encoded string
|
|
290
|
+
*/
|
|
291
|
+
function rstr2hex(input) {
|
|
292
|
+
const hexTab = '0123456789abcdef';
|
|
293
|
+
let output = '';
|
|
294
|
+
let x;
|
|
295
|
+
let i;
|
|
296
|
+
for (i = 0; i < input.length; i += 1) {
|
|
297
|
+
x = input.charCodeAt(i);
|
|
298
|
+
output += hexTab.charAt((x >>> 4) & 0x0f) + hexTab.charAt(x & 0x0f);
|
|
299
|
+
}
|
|
300
|
+
return output;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Encode a string as UTF-8
|
|
305
|
+
*
|
|
306
|
+
* @param {string} input Input string
|
|
307
|
+
* @returns {string} UTF8 string
|
|
308
|
+
*/
|
|
309
|
+
function str2rstrUTF8(input) {
|
|
310
|
+
return unescape(encodeURIComponent(input));
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Encodes input string as raw MD5 string
|
|
315
|
+
*
|
|
316
|
+
* @param {string} s Input string
|
|
317
|
+
* @returns {string} Raw MD5 string
|
|
318
|
+
*/
|
|
319
|
+
function rawMD5(s) {
|
|
320
|
+
return rstrMD5(str2rstrUTF8(s));
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Encodes input string as Hex encoded string
|
|
324
|
+
*
|
|
325
|
+
* @param {string} s Input string
|
|
326
|
+
* @returns {string} Hex encoded string
|
|
327
|
+
*/
|
|
328
|
+
function hexMD5(s) {
|
|
329
|
+
return rstr2hex(rawMD5(s));
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Calculates the raw HMAC-MD5 for the given key and data
|
|
333
|
+
*
|
|
334
|
+
* @param {string} k HMAC key
|
|
335
|
+
* @param {string} d Input string
|
|
336
|
+
* @returns {string} Raw MD5 string
|
|
337
|
+
*/
|
|
338
|
+
function rawHMACMD5(k, d) {
|
|
339
|
+
return rstrHMACMD5(str2rstrUTF8(k), str2rstrUTF8(d));
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Calculates the Hex encoded HMAC-MD5 for the given key and data
|
|
343
|
+
*
|
|
344
|
+
* @param {string} k HMAC key
|
|
345
|
+
* @param {string} d Input string
|
|
346
|
+
* @returns {string} Raw MD5 string
|
|
347
|
+
*/
|
|
348
|
+
function hexHMACMD5(k, d) {
|
|
349
|
+
return rstr2hex(rawHMACMD5(k, d));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Calculates MD5 value for a given string.
|
|
354
|
+
* If a key is provided, calculates the HMAC-MD5 value.
|
|
355
|
+
* Returns a Hex encoded string unless the raw argument is given.
|
|
356
|
+
*
|
|
357
|
+
* @param {string} string Input string
|
|
358
|
+
* @param {string} [key] HMAC key
|
|
359
|
+
* @param {boolean} [raw] Raw output switch
|
|
360
|
+
* @returns {string} MD5 output
|
|
361
|
+
*/
|
|
362
|
+
function md5(string, key, raw) {
|
|
363
|
+
if (!key) {
|
|
364
|
+
if (!raw) {
|
|
365
|
+
return hexMD5(string);
|
|
127
366
|
}
|
|
128
|
-
return
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const kiArr = ('16b05af49e38d27c58be147ad0369cf207e5c3a18f6d4b29').split('').map(n => parseInt(n, 16));
|
|
133
|
-
const hxArr = [
|
|
134
|
-
0xD76AA478, 0xE8C7B756, 0x242070DB, 0xC1BDCEEE, 0xF57C0FAF, 0x4787C62A, 0xA8304613, 0xFD469501,
|
|
135
|
-
0x698098D8, 0x8B44F7AF, 0xFFFF5BB1, 0x895CD7BE, 0x6B901122, 0xFD987193, 0xA679438E, 0x49B40821,
|
|
136
|
-
0xF61E2562, 0xC040B340, 0x265E5A51, 0xE9B6C7AA, 0xD62F105D, 0x2441453, 0xD8A1E681, 0xE7D3FBC8,
|
|
137
|
-
0x21E1CDE6, 0xC33707D6, 0xF4D50D87, 0x455A14ED, 0xA9E3E905, 0xFCEFA3F8, 0x676F02D9, 0x8D2A4C8A,
|
|
138
|
-
0xFFFA3942, 0x8771F681, 0x6D9D6122, 0xFDE5380C, 0xA4BEEA44, 0x4BDECFA9, 0xF6BB4B60, 0xBEBFBC70,
|
|
139
|
-
0x289B7EC6, 0xEAA127FA, 0xD4EF3085, 0x4881D05, 0xD9D4D039, 0xE6DB99E5, 0x1FA27CF8, 0xC4AC5665,
|
|
140
|
-
0xF4292244, 0x432AFF97, 0xAB9423A7, 0xFC93A039, 0x655B59C3, 0x8F0CCC92, 0xFFEFF47D, 0x85845DD1,
|
|
141
|
-
0x6FA87E4F, 0xFE2CE6E0, 0xA3014314, 0x4E0811A1, 0xF7537E82, 0xBD3AF235, 0x2AD7D2BB, 0xEB86D391,
|
|
142
|
-
];
|
|
143
|
-
// eslint-disable-next-line require-jsdoc
|
|
144
|
-
const cyc = (i, r = 0) => (i + r) % 4;
|
|
145
|
-
// 4组处理位操作函数
|
|
146
|
-
// eslint-disable-next-line require-jsdoc
|
|
147
|
-
const md5F = (x, y, z) => (x & y) | ((~x) & z);
|
|
148
|
-
// eslint-disable-next-line require-jsdoc
|
|
149
|
-
const md5G = (x, y, z) => (x & z) | (y & (~z));
|
|
150
|
-
// eslint-disable-next-line require-jsdoc
|
|
151
|
-
const md5H = (x, y, z) => (x ^ y ^ z);
|
|
152
|
-
// eslint-disable-next-line require-jsdoc
|
|
153
|
-
const md5I = (x, y, z) => (y ^ (x | (~z)));
|
|
154
|
-
const string = encodeUtf8(str);
|
|
155
|
-
const x = convertToWordArray(string);
|
|
156
|
-
for (let k = 0; k < x.length; k += 16) {
|
|
157
|
-
const AA = a;
|
|
158
|
-
const BB = b;
|
|
159
|
-
const CC = c;
|
|
160
|
-
const DD = d;
|
|
161
|
-
const arr = [a, d, c, b];
|
|
162
|
-
hxArr.forEach((hx, m) => {
|
|
163
|
-
const i = m % 16;
|
|
164
|
-
const g = m / 16 << 0;
|
|
165
|
-
const ki = m < 16 ? m : kiArr[m - 16];
|
|
166
|
-
const FN = [md5F, md5G, md5H, md5I][g];
|
|
167
|
-
|
|
168
|
-
arr[cyc(i)] = addRecycling({
|
|
169
|
-
FN,
|
|
170
|
-
a: arr[cyc(i)],
|
|
171
|
-
b: arr[cyc(i, 3)],
|
|
172
|
-
c: arr[cyc(i, 2)],
|
|
173
|
-
d: arr[cyc(i, 1)],
|
|
174
|
-
x: x[k + ki],
|
|
175
|
-
s: sArr[g][i % 4],
|
|
176
|
-
ac: hx,
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
a = addUnsigned(arr[0], AA);
|
|
180
|
-
b = addUnsigned(arr[3], BB);
|
|
181
|
-
c = addUnsigned(arr[2], CC);
|
|
182
|
-
d = addUnsigned(arr[1], DD);
|
|
367
|
+
return rawMD5(string);
|
|
368
|
+
}
|
|
369
|
+
if (!raw) {
|
|
370
|
+
return hexHMACMD5(key, string);
|
|
183
371
|
}
|
|
184
|
-
return (
|
|
185
|
-
}
|
|
372
|
+
return rawHMACMD5(key, string);
|
|
373
|
+
}
|
|
186
374
|
|
|
187
375
|
export default md5;
|
package/src/request.js
CHANGED
|
@@ -256,7 +256,7 @@ export default class Request {
|
|
|
256
256
|
name: 'content',
|
|
257
257
|
url: this.makeUrl(path),
|
|
258
258
|
filePath,
|
|
259
|
-
formData: sign(requestParam),
|
|
259
|
+
formData: sign(requestParam, this.secretKey),
|
|
260
260
|
header,
|
|
261
261
|
success: resolve,
|
|
262
262
|
fail: reject,
|
|
@@ -297,7 +297,7 @@ export default class Request {
|
|
|
297
297
|
async serialize(path, data = {}) {
|
|
298
298
|
let url = this.makeUrl(path);
|
|
299
299
|
const signData = await composeParam(data, this.withAuth, this.baseParam);
|
|
300
|
-
const signature = sign(signData);
|
|
300
|
+
const signature = sign(signData, this.secretKey);
|
|
301
301
|
const params = [];
|
|
302
302
|
Object.keys(signature).forEach((key) => {
|
|
303
303
|
const val = encodeURIComponent(signature[key]);
|