js-md5 0.7.2 → 0.8.0
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/CHANGELOG.md +21 -0
- package/LICENSE.txt +1 -1
- package/README.md +18 -2
- package/build/md5.min.js +3 -3
- package/index.d.ts +148 -0
- package/package.json +15 -10
- package/src/md5.js +272 -79
- package/.covignore +0 -2
- package/.npmignore +0 -2
- package/.travis.yml +0 -11
- package/bower.json +0 -8
- package/doc/Md5_.html +0 -1194
- package/doc/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/doc/fonts/OpenSans-Bold-webfont.svg +0 -1830
- package/doc/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/doc/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/doc/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
- package/doc/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/doc/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/doc/fonts/OpenSans-Italic-webfont.svg +0 -1830
- package/doc/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/doc/fonts/OpenSans-Light-webfont.eot +0 -0
- package/doc/fonts/OpenSans-Light-webfont.svg +0 -1831
- package/doc/fonts/OpenSans-Light-webfont.woff +0 -0
- package/doc/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/doc/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
- package/doc/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/doc/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/doc/fonts/OpenSans-Regular-webfont.svg +0 -1831
- package/doc/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/doc/global.html +0 -309
- package/doc/index.html +0 -105
- package/doc/md5.html +0 -1469
- package/doc/md5.js.html +0 -734
- package/doc/scripts/linenumber.js +0 -25
- package/doc/scripts/prettify/Apache-License-2.0.txt +0 -202
- package/doc/scripts/prettify/lang-css.js +0 -2
- package/doc/scripts/prettify/prettify.js +0 -28
- package/doc/styles/jsdoc-default.css +0 -358
- package/doc/styles/prettify-jsdoc.css +0 -111
- package/doc/styles/prettify-tomorrow.css +0 -132
- package/tests/index.html +0 -22
- package/tests/node-test.js +0 -100
- package/tests/requirejs.html +0 -24
- package/tests/test.js +0 -270
- package/tests/worker-test.js +0 -21
- package/tests/worker.html +0 -26
- package/tests/worker.js +0 -12
package/src/md5.js
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
* [js-md5]{@link https://github.com/emn178/js-md5}
|
|
3
3
|
*
|
|
4
4
|
* @namespace md5
|
|
5
|
-
* @version 0.
|
|
5
|
+
* @version 0.8.0
|
|
6
6
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
7
|
-
* @copyright Chen, Yi-Cyuan 2014-
|
|
7
|
+
* @copyright Chen, Yi-Cyuan 2014-2023
|
|
8
8
|
* @license MIT
|
|
9
9
|
*/
|
|
10
10
|
(function () {
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var INPUT_ERROR = 'input is invalid type';
|
|
14
|
+
var FINALIZE_ERROR = 'finalize already called';
|
|
14
15
|
var WINDOW = typeof window === 'object';
|
|
15
16
|
var root = WINDOW ? window : {};
|
|
16
17
|
if (root.JS_MD5_NO_WINDOW) {
|
|
@@ -39,18 +40,38 @@
|
|
|
39
40
|
blocks = new Uint32Array(buffer);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
var isArray = Array.isArray;
|
|
44
|
+
if (root.JS_MD5_NO_NODE_JS || !isArray) {
|
|
45
|
+
isArray = function (obj) {
|
|
44
46
|
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
45
47
|
};
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
var isView = ArrayBuffer.isView;
|
|
51
|
+
if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
|
|
52
|
+
isView = function (obj) {
|
|
50
53
|
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
|
|
51
54
|
};
|
|
52
55
|
}
|
|
53
56
|
|
|
57
|
+
// [message: string, isString: bool]
|
|
58
|
+
var formatMessage = function (message) {
|
|
59
|
+
var type = typeof message;
|
|
60
|
+
if (type === 'string') {
|
|
61
|
+
return [message, true];
|
|
62
|
+
}
|
|
63
|
+
if (type !== 'object' || message === null) {
|
|
64
|
+
throw new Error(INPUT_ERROR);
|
|
65
|
+
}
|
|
66
|
+
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
67
|
+
return [new Uint8Array(message), false];
|
|
68
|
+
}
|
|
69
|
+
if (!isArray(message) && !isView(message)) {
|
|
70
|
+
throw new Error(INPUT_ERROR);
|
|
71
|
+
}
|
|
72
|
+
return [message, false];
|
|
73
|
+
}
|
|
74
|
+
|
|
54
75
|
/**
|
|
55
76
|
* @method hex
|
|
56
77
|
* @memberof md5
|
|
@@ -153,21 +174,29 @@
|
|
|
153
174
|
};
|
|
154
175
|
|
|
155
176
|
var nodeWrap = function (method) {
|
|
156
|
-
var crypto =
|
|
157
|
-
var Buffer =
|
|
177
|
+
var crypto = require('crypto')
|
|
178
|
+
var Buffer = require('buffer').Buffer;
|
|
179
|
+
var bufferFrom;
|
|
180
|
+
if (Buffer.from && !root.JS_MD5_NO_BUFFER_FROM) {
|
|
181
|
+
bufferFrom = Buffer.from;
|
|
182
|
+
} else {
|
|
183
|
+
bufferFrom = function (message) {
|
|
184
|
+
return new Buffer(message);
|
|
185
|
+
};
|
|
186
|
+
}
|
|
158
187
|
var nodeMethod = function (message) {
|
|
159
188
|
if (typeof message === 'string') {
|
|
160
189
|
return crypto.createHash('md5').update(message, 'utf8').digest('hex');
|
|
161
190
|
} else {
|
|
162
191
|
if (message === null || message === undefined) {
|
|
163
|
-
throw
|
|
192
|
+
throw new Error(INPUT_ERROR);
|
|
164
193
|
} else if (message.constructor === ArrayBuffer) {
|
|
165
194
|
message = new Uint8Array(message);
|
|
166
195
|
}
|
|
167
196
|
}
|
|
168
|
-
if (
|
|
197
|
+
if (isArray(message) || isView(message) ||
|
|
169
198
|
message.constructor === Buffer) {
|
|
170
|
-
return crypto.createHash('md5').update(
|
|
199
|
+
return crypto.createHash('md5').update(bufferFrom(message)).digest('hex');
|
|
171
200
|
} else {
|
|
172
201
|
return method(message);
|
|
173
202
|
}
|
|
@@ -175,6 +204,116 @@
|
|
|
175
204
|
return nodeMethod;
|
|
176
205
|
};
|
|
177
206
|
|
|
207
|
+
/**
|
|
208
|
+
* @namespace md5.hmac
|
|
209
|
+
*/
|
|
210
|
+
/**
|
|
211
|
+
* @method hex
|
|
212
|
+
* @memberof md5.hmac
|
|
213
|
+
* @description Output hash as hex string
|
|
214
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} key key
|
|
215
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
216
|
+
* @returns {String} Hex string
|
|
217
|
+
* @example
|
|
218
|
+
* md5.hmac.hex('key', 'The quick brown fox jumps over the lazy dog');
|
|
219
|
+
* // equal to
|
|
220
|
+
* md5.hmac('key', 'The quick brown fox jumps over the lazy dog');
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @method digest
|
|
225
|
+
* @memberof md5.hmac
|
|
226
|
+
* @description Output hash as bytes array
|
|
227
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} key key
|
|
228
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
229
|
+
* @returns {Array} Bytes array
|
|
230
|
+
* @example
|
|
231
|
+
* md5.hmac.digest('key', 'The quick brown fox jumps over the lazy dog');
|
|
232
|
+
*/
|
|
233
|
+
/**
|
|
234
|
+
* @method array
|
|
235
|
+
* @memberof md5.hmac
|
|
236
|
+
* @description Output hash as bytes array
|
|
237
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} key key
|
|
238
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
239
|
+
* @returns {Array} Bytes array
|
|
240
|
+
* @example
|
|
241
|
+
* md5.hmac.array('key', 'The quick brown fox jumps over the lazy dog');
|
|
242
|
+
*/
|
|
243
|
+
/**
|
|
244
|
+
* @method arrayBuffer
|
|
245
|
+
* @memberof md5.hmac
|
|
246
|
+
* @description Output hash as ArrayBuffer
|
|
247
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} key key
|
|
248
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
249
|
+
* @returns {ArrayBuffer} ArrayBuffer
|
|
250
|
+
* @example
|
|
251
|
+
* md5.hmac.arrayBuffer('key', 'The quick brown fox jumps over the lazy dog');
|
|
252
|
+
*/
|
|
253
|
+
/**
|
|
254
|
+
* @method buffer
|
|
255
|
+
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
|
|
256
|
+
* @memberof md5.hmac
|
|
257
|
+
* @description Output hash as ArrayBuffer
|
|
258
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} key key
|
|
259
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
260
|
+
* @returns {ArrayBuffer} ArrayBuffer
|
|
261
|
+
* @example
|
|
262
|
+
* md5.hmac.buffer('key', 'The quick brown fox jumps over the lazy dog');
|
|
263
|
+
*/
|
|
264
|
+
/**
|
|
265
|
+
* @method base64
|
|
266
|
+
* @memberof md5.hmac
|
|
267
|
+
* @description Output hash as base64 string
|
|
268
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} key key
|
|
269
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
270
|
+
* @returns {String} base64 string
|
|
271
|
+
* @example
|
|
272
|
+
* md5.hmac.base64('key', 'The quick brown fox jumps over the lazy dog');
|
|
273
|
+
*/
|
|
274
|
+
var createHmacOutputMethod = function (outputType) {
|
|
275
|
+
return function (key, message) {
|
|
276
|
+
return new HmacMd5(key, true).update(message)[outputType]();
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* @method create
|
|
282
|
+
* @memberof md5.hmac
|
|
283
|
+
* @description Create HmacMd5 object
|
|
284
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} key key
|
|
285
|
+
* @returns {HmacMd5} HmacMd5 object.
|
|
286
|
+
* @example
|
|
287
|
+
* var hash = md5.hmac.create('key');
|
|
288
|
+
*/
|
|
289
|
+
/**
|
|
290
|
+
* @method update
|
|
291
|
+
* @memberof md5.hmac
|
|
292
|
+
* @description Create and update HmacMd5 object
|
|
293
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} key key
|
|
294
|
+
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
|
295
|
+
* @returns {HmacMd5} HmacMd5 object.
|
|
296
|
+
* @example
|
|
297
|
+
* var hash = md5.hmac.update('key', 'The quick brown fox jumps over the lazy dog');
|
|
298
|
+
* // equal to
|
|
299
|
+
* var hash = md5.hmac.create('key');
|
|
300
|
+
* hash.update('The quick brown fox jumps over the lazy dog');
|
|
301
|
+
*/
|
|
302
|
+
var createHmacMethod = function () {
|
|
303
|
+
var method = createHmacOutputMethod('hex');
|
|
304
|
+
method.create = function (key) {
|
|
305
|
+
return new HmacMd5(key);
|
|
306
|
+
};
|
|
307
|
+
method.update = function (key, message) {
|
|
308
|
+
return method.create(key).update(message);
|
|
309
|
+
};
|
|
310
|
+
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
311
|
+
var type = OUTPUT_TYPES[i];
|
|
312
|
+
method[type] = createHmacOutputMethod(type);
|
|
313
|
+
}
|
|
314
|
+
return method;
|
|
315
|
+
};
|
|
316
|
+
|
|
178
317
|
/**
|
|
179
318
|
* Md5 class
|
|
180
319
|
* @class Md5
|
|
@@ -214,26 +353,12 @@
|
|
|
214
353
|
*/
|
|
215
354
|
Md5.prototype.update = function (message) {
|
|
216
355
|
if (this.finalized) {
|
|
217
|
-
|
|
356
|
+
throw new Error(FINALIZE_ERROR);
|
|
218
357
|
}
|
|
219
358
|
|
|
220
|
-
var
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (message === null) {
|
|
224
|
-
throw ERROR;
|
|
225
|
-
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
226
|
-
message = new Uint8Array(message);
|
|
227
|
-
} else if (!Array.isArray(message)) {
|
|
228
|
-
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
|
|
229
|
-
throw ERROR;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
} else {
|
|
233
|
-
throw ERROR;
|
|
234
|
-
}
|
|
235
|
-
notString = true;
|
|
236
|
-
}
|
|
359
|
+
var result = formatMessage(message);
|
|
360
|
+
message = result[0];
|
|
361
|
+
var isString = result[1];
|
|
237
362
|
var code, index = 0, i, length = message.length, blocks = this.blocks;
|
|
238
363
|
var buffer8 = this.buffer8;
|
|
239
364
|
|
|
@@ -247,34 +372,24 @@
|
|
|
247
372
|
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
248
373
|
}
|
|
249
374
|
|
|
250
|
-
if (
|
|
251
|
-
if (ARRAY_BUFFER) {
|
|
252
|
-
for (i = this.start; index < length && i < 64; ++index) {
|
|
253
|
-
buffer8[i++] = message[index];
|
|
254
|
-
}
|
|
255
|
-
} else {
|
|
256
|
-
for (i = this.start; index < length && i < 64; ++index) {
|
|
257
|
-
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
} else {
|
|
375
|
+
if (isString) {
|
|
261
376
|
if (ARRAY_BUFFER) {
|
|
262
377
|
for (i = this.start; index < length && i < 64; ++index) {
|
|
263
378
|
code = message.charCodeAt(index);
|
|
264
379
|
if (code < 0x80) {
|
|
265
380
|
buffer8[i++] = code;
|
|
266
381
|
} else if (code < 0x800) {
|
|
267
|
-
buffer8[i++] = 0xc0 | (code
|
|
382
|
+
buffer8[i++] = 0xc0 | (code >>> 6);
|
|
268
383
|
buffer8[i++] = 0x80 | (code & 0x3f);
|
|
269
384
|
} else if (code < 0xd800 || code >= 0xe000) {
|
|
270
|
-
buffer8[i++] = 0xe0 | (code
|
|
271
|
-
buffer8[i++] = 0x80 | ((code
|
|
385
|
+
buffer8[i++] = 0xe0 | (code >>> 12);
|
|
386
|
+
buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
|
|
272
387
|
buffer8[i++] = 0x80 | (code & 0x3f);
|
|
273
388
|
} else {
|
|
274
389
|
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
|
275
|
-
buffer8[i++] = 0xf0 | (code
|
|
276
|
-
buffer8[i++] = 0x80 | ((code
|
|
277
|
-
buffer8[i++] = 0x80 | ((code
|
|
390
|
+
buffer8[i++] = 0xf0 | (code >>> 18);
|
|
391
|
+
buffer8[i++] = 0x80 | ((code >>> 12) & 0x3f);
|
|
392
|
+
buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
|
|
278
393
|
buffer8[i++] = 0x80 | (code & 0x3f);
|
|
279
394
|
}
|
|
280
395
|
}
|
|
@@ -282,23 +397,33 @@
|
|
|
282
397
|
for (i = this.start; index < length && i < 64; ++index) {
|
|
283
398
|
code = message.charCodeAt(index);
|
|
284
399
|
if (code < 0x80) {
|
|
285
|
-
blocks[i
|
|
400
|
+
blocks[i >>> 2] |= code << SHIFT[i++ & 3];
|
|
286
401
|
} else if (code < 0x800) {
|
|
287
|
-
blocks[i
|
|
288
|
-
blocks[i
|
|
402
|
+
blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3];
|
|
403
|
+
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
289
404
|
} else if (code < 0xd800 || code >= 0xe000) {
|
|
290
|
-
blocks[i
|
|
291
|
-
blocks[i
|
|
292
|
-
blocks[i
|
|
405
|
+
blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3];
|
|
406
|
+
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
407
|
+
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
293
408
|
} else {
|
|
294
409
|
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
|
295
|
-
blocks[i
|
|
296
|
-
blocks[i
|
|
297
|
-
blocks[i
|
|
298
|
-
blocks[i
|
|
410
|
+
blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3];
|
|
411
|
+
blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3];
|
|
412
|
+
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
413
|
+
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
299
414
|
}
|
|
300
415
|
}
|
|
301
416
|
}
|
|
417
|
+
} else {
|
|
418
|
+
if (ARRAY_BUFFER) {
|
|
419
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
420
|
+
buffer8[i++] = message[index];
|
|
421
|
+
}
|
|
422
|
+
} else {
|
|
423
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
424
|
+
blocks[i >>> 2] |= message[index] << SHIFT[i++ & 3];
|
|
425
|
+
}
|
|
426
|
+
}
|
|
302
427
|
}
|
|
303
428
|
this.lastByteIndex = i;
|
|
304
429
|
this.bytes += i - this.start;
|
|
@@ -323,7 +448,7 @@
|
|
|
323
448
|
}
|
|
324
449
|
this.finalized = true;
|
|
325
450
|
var blocks = this.blocks, i = this.lastByteIndex;
|
|
326
|
-
blocks[i
|
|
451
|
+
blocks[i >>> 2] |= EXTRA[i & 3];
|
|
327
452
|
if (i >= 56) {
|
|
328
453
|
if (!this.hashed) {
|
|
329
454
|
this.hash();
|
|
@@ -335,7 +460,7 @@
|
|
|
335
460
|
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
336
461
|
}
|
|
337
462
|
blocks[14] = this.bytes << 3;
|
|
338
|
-
blocks[15] = this.hBytes << 3 | this.bytes
|
|
463
|
+
blocks[15] = this.hBytes << 3 | this.bytes >>> 29;
|
|
339
464
|
this.hash();
|
|
340
465
|
};
|
|
341
466
|
|
|
@@ -524,22 +649,22 @@
|
|
|
524
649
|
|
|
525
650
|
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
|
|
526
651
|
|
|
527
|
-
return HEX_CHARS[(h0
|
|
528
|
-
HEX_CHARS[(h0
|
|
529
|
-
HEX_CHARS[(h0
|
|
530
|
-
HEX_CHARS[(h0
|
|
531
|
-
HEX_CHARS[(h1
|
|
532
|
-
HEX_CHARS[(h1
|
|
533
|
-
HEX_CHARS[(h1
|
|
534
|
-
HEX_CHARS[(h1
|
|
535
|
-
HEX_CHARS[(h2
|
|
536
|
-
HEX_CHARS[(h2
|
|
537
|
-
HEX_CHARS[(h2
|
|
538
|
-
HEX_CHARS[(h2
|
|
539
|
-
HEX_CHARS[(h3
|
|
540
|
-
HEX_CHARS[(h3
|
|
541
|
-
HEX_CHARS[(h3
|
|
542
|
-
HEX_CHARS[(h3
|
|
652
|
+
return HEX_CHARS[(h0 >>> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
|
|
653
|
+
HEX_CHARS[(h0 >>> 12) & 0x0F] + HEX_CHARS[(h0 >>> 8) & 0x0F] +
|
|
654
|
+
HEX_CHARS[(h0 >>> 20) & 0x0F] + HEX_CHARS[(h0 >>> 16) & 0x0F] +
|
|
655
|
+
HEX_CHARS[(h0 >>> 28) & 0x0F] + HEX_CHARS[(h0 >>> 24) & 0x0F] +
|
|
656
|
+
HEX_CHARS[(h1 >>> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
|
|
657
|
+
HEX_CHARS[(h1 >>> 12) & 0x0F] + HEX_CHARS[(h1 >>> 8) & 0x0F] +
|
|
658
|
+
HEX_CHARS[(h1 >>> 20) & 0x0F] + HEX_CHARS[(h1 >>> 16) & 0x0F] +
|
|
659
|
+
HEX_CHARS[(h1 >>> 28) & 0x0F] + HEX_CHARS[(h1 >>> 24) & 0x0F] +
|
|
660
|
+
HEX_CHARS[(h2 >>> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
|
|
661
|
+
HEX_CHARS[(h2 >>> 12) & 0x0F] + HEX_CHARS[(h2 >>> 8) & 0x0F] +
|
|
662
|
+
HEX_CHARS[(h2 >>> 20) & 0x0F] + HEX_CHARS[(h2 >>> 16) & 0x0F] +
|
|
663
|
+
HEX_CHARS[(h2 >>> 28) & 0x0F] + HEX_CHARS[(h2 >>> 24) & 0x0F] +
|
|
664
|
+
HEX_CHARS[(h3 >>> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
|
|
665
|
+
HEX_CHARS[(h3 >>> 12) & 0x0F] + HEX_CHARS[(h3 >>> 8) & 0x0F] +
|
|
666
|
+
HEX_CHARS[(h3 >>> 20) & 0x0F] + HEX_CHARS[(h3 >>> 16) & 0x0F] +
|
|
667
|
+
HEX_CHARS[(h3 >>> 28) & 0x0F] + HEX_CHARS[(h3 >>> 24) & 0x0F];
|
|
543
668
|
};
|
|
544
669
|
|
|
545
670
|
/**
|
|
@@ -569,10 +694,10 @@
|
|
|
569
694
|
|
|
570
695
|
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
|
|
571
696
|
return [
|
|
572
|
-
h0 & 0xFF, (h0
|
|
573
|
-
h1 & 0xFF, (h1
|
|
574
|
-
h2 & 0xFF, (h2
|
|
575
|
-
h3 & 0xFF, (h3
|
|
697
|
+
h0 & 0xFF, (h0 >>> 8) & 0xFF, (h0 >>> 16) & 0xFF, (h0 >>> 24) & 0xFF,
|
|
698
|
+
h1 & 0xFF, (h1 >>> 8) & 0xFF, (h1 >>> 16) & 0xFF, (h1 >>> 24) & 0xFF,
|
|
699
|
+
h2 & 0xFF, (h2 >>> 8) & 0xFF, (h2 >>> 16) & 0xFF, (h2 >>> 24) & 0xFF,
|
|
700
|
+
h3 & 0xFF, (h3 >>> 8) & 0xFF, (h3 >>> 16) & 0xFF, (h3 >>> 24) & 0xFF
|
|
576
701
|
];
|
|
577
702
|
};
|
|
578
703
|
|
|
@@ -651,7 +776,75 @@
|
|
|
651
776
|
return base64Str;
|
|
652
777
|
};
|
|
653
778
|
|
|
779
|
+
/**
|
|
780
|
+
* HmacMd5 class
|
|
781
|
+
* @class HmacMd5
|
|
782
|
+
* @extends Md5
|
|
783
|
+
* @description This is internal class.
|
|
784
|
+
* @see {@link md5.hmac.create}
|
|
785
|
+
*/
|
|
786
|
+
function HmacMd5(key, sharedMemory) {
|
|
787
|
+
var i, result = formatMessage(key);
|
|
788
|
+
key = result[0];
|
|
789
|
+
if (result[1]) {
|
|
790
|
+
var bytes = [], length = key.length, index = 0, code;
|
|
791
|
+
for (i = 0; i < length; ++i) {
|
|
792
|
+
code = key.charCodeAt(i);
|
|
793
|
+
if (code < 0x80) {
|
|
794
|
+
bytes[index++] = code;
|
|
795
|
+
} else if (code < 0x800) {
|
|
796
|
+
bytes[index++] = (0xc0 | (code >>> 6));
|
|
797
|
+
bytes[index++] = (0x80 | (code & 0x3f));
|
|
798
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
799
|
+
bytes[index++] = (0xe0 | (code >>> 12));
|
|
800
|
+
bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
|
|
801
|
+
bytes[index++] = (0x80 | (code & 0x3f));
|
|
802
|
+
} else {
|
|
803
|
+
code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff));
|
|
804
|
+
bytes[index++] = (0xf0 | (code >>> 18));
|
|
805
|
+
bytes[index++] = (0x80 | ((code >>> 12) & 0x3f));
|
|
806
|
+
bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
|
|
807
|
+
bytes[index++] = (0x80 | (code & 0x3f));
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
key = bytes;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
if (key.length > 64) {
|
|
814
|
+
key = (new Md5(true)).update(key).array();
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
var oKeyPad = [], iKeyPad = [];
|
|
818
|
+
for (i = 0; i < 64; ++i) {
|
|
819
|
+
var b = key[i] || 0;
|
|
820
|
+
oKeyPad[i] = 0x5c ^ b;
|
|
821
|
+
iKeyPad[i] = 0x36 ^ b;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
Md5.call(this, sharedMemory);
|
|
825
|
+
|
|
826
|
+
this.update(iKeyPad);
|
|
827
|
+
this.oKeyPad = oKeyPad;
|
|
828
|
+
this.inner = true;
|
|
829
|
+
this.sharedMemory = sharedMemory;
|
|
830
|
+
}
|
|
831
|
+
HmacMd5.prototype = new Md5();
|
|
832
|
+
|
|
833
|
+
HmacMd5.prototype.finalize = function () {
|
|
834
|
+
Md5.prototype.finalize.call(this);
|
|
835
|
+
if (this.inner) {
|
|
836
|
+
this.inner = false;
|
|
837
|
+
var innerHash = this.array();
|
|
838
|
+
Md5.call(this, this.sharedMemory);
|
|
839
|
+
this.update(this.oKeyPad);
|
|
840
|
+
this.update(innerHash);
|
|
841
|
+
Md5.prototype.finalize.call(this);
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
|
|
654
845
|
var exports = createMethod();
|
|
846
|
+
exports.md5 = exports;
|
|
847
|
+
exports.md5.hmac = createHmacMethod();
|
|
655
848
|
|
|
656
849
|
if (COMMON_JS) {
|
|
657
850
|
module.exports = exports;
|
package/.covignore
DELETED
package/.npmignore
DELETED
package/.travis.yml
DELETED