js-md5 0.8.2 → 0.9.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/build/md5.mjs ADDED
@@ -0,0 +1,870 @@
1
+ function getDefaultExportFromCjs (x) {
2
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
3
+ }
4
+
5
+ var md5$1 = {exports: {}};
6
+
7
+ /**
8
+ * [js-md5]{@link https://github.com/emn178/js-md5}
9
+ *
10
+ * @namespace md5
11
+ * @version 0.9.0
12
+ * @author Chen, Yi-Cyuan [emn178@gmail.com]
13
+ * @copyright Chen, Yi-Cyuan 2014-2026
14
+ * @license MIT
15
+ */
16
+
17
+ (function (module) {
18
+ (function () {
19
+
20
+ var INPUT_ERROR = 'input is invalid type';
21
+ var FINALIZE_ERROR = 'finalize already called';
22
+ var WINDOW = typeof window === 'object';
23
+ var root = WINDOW ? window : {};
24
+ if (root.JS_MD5_NO_WINDOW) {
25
+ WINDOW = false;
26
+ }
27
+ var WEB_WORKER = !WINDOW && typeof self === 'object';
28
+ if (WEB_WORKER) {
29
+ root = self;
30
+ }
31
+ var COMMON_JS = !root.JS_MD5_NO_COMMON_JS && 'object' === 'object' && module.exports;
32
+ /* istanbul ignore next */
33
+ var ARRAY_BUFFER = !root.JS_MD5_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined' ;
34
+ var HEX_CHARS = '0123456789abcdef'.split('');
35
+ var EXTRA = [128, 32768, 8388608, -2147483648];
36
+ var SHIFT = [0, 8, 16, 24];
37
+ var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'];
38
+ /* istanbul ignore else */
39
+ {
40
+ OUTPUT_TYPES.push('buffer');
41
+ }
42
+ /* istanbul ignore else */
43
+ {
44
+ OUTPUT_TYPES.push('base64');
45
+ }
46
+ /* istanbul ignore next */
47
+ var BASE64_ENCODE_CHAR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('') ;
48
+
49
+ var blocks = [], buffer8;
50
+ if (ARRAY_BUFFER) {
51
+ var buffer = new ArrayBuffer(68);
52
+ buffer8 = new Uint8Array(buffer);
53
+ blocks = new Uint32Array(buffer);
54
+ }
55
+
56
+ var isArray = Array.isArray;
57
+ /* istanbul ignore else */
58
+ if ((root.JS_MD5_NO_NODE_JS || !isArray)) {
59
+ isArray = function (obj) {
60
+ return Object.prototype.toString.call(obj) === '[object Array]';
61
+ };
62
+ }
63
+
64
+ var isView = ArrayBuffer.isView;
65
+ /* istanbul ignore else */
66
+ if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
67
+ isView = function (obj) {
68
+ return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
69
+ };
70
+ }
71
+
72
+ // [message: string, isString: bool]
73
+ var formatMessage = function (message) {
74
+ var type = typeof message;
75
+ if (type === 'string') {
76
+ return [message, true];
77
+ }
78
+ if (type !== 'object' || message === null) {
79
+ throw new Error(INPUT_ERROR);
80
+ }
81
+ if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
82
+ return [new Uint8Array(message), false];
83
+ }
84
+ if (!isArray(message) && !isView(message)) {
85
+ throw new Error(INPUT_ERROR);
86
+ }
87
+ return [message, false];
88
+ };
89
+
90
+ /**
91
+ * @method hex
92
+ * @memberof md5
93
+ * @description Output hash as hex string
94
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
95
+ * @returns {String} Hex string
96
+ * @example
97
+ * md5.hex('The quick brown fox jumps over the lazy dog');
98
+ * // equal to
99
+ * md5('The quick brown fox jumps over the lazy dog');
100
+ */
101
+ /**
102
+ * @method digest
103
+ * @memberof md5
104
+ * @description Output hash as bytes array
105
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
106
+ * @returns {Array} Bytes array
107
+ * @example
108
+ * md5.digest('The quick brown fox jumps over the lazy dog');
109
+ */
110
+ /**
111
+ * @method array
112
+ * @memberof md5
113
+ * @description Output hash as bytes array
114
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
115
+ * @returns {Array} Bytes array
116
+ * @example
117
+ * md5.array('The quick brown fox jumps over the lazy dog');
118
+ */
119
+ /**
120
+ * @method arrayBuffer
121
+ * @memberof md5
122
+ * @description Output hash as ArrayBuffer
123
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
124
+ * @returns {ArrayBuffer} ArrayBuffer
125
+ * @example
126
+ * md5.arrayBuffer('The quick brown fox jumps over the lazy dog');
127
+ */
128
+ /**
129
+ * @method buffer
130
+ * @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
131
+ * @memberof md5
132
+ * @description Output hash as ArrayBuffer
133
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
134
+ * @returns {ArrayBuffer} ArrayBuffer
135
+ * @example
136
+ * md5.buffer('The quick brown fox jumps over the lazy dog');
137
+ */
138
+ /**
139
+ * @method base64
140
+ * @memberof md5
141
+ * @description Output hash as base64 string
142
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
143
+ * @returns {String} base64 string
144
+ * @example
145
+ * md5.base64('The quick brown fox jumps over the lazy dog');
146
+ */
147
+ var createOutputMethod = function (outputType) {
148
+ return function (message) {
149
+ return new Md5(true).update(message)[outputType]();
150
+ };
151
+ };
152
+
153
+ /**
154
+ * @method create
155
+ * @memberof md5
156
+ * @description Create Md5 object
157
+ * @returns {Md5} Md5 object.
158
+ * @example
159
+ * var hash = md5.create();
160
+ */
161
+ /**
162
+ * @method update
163
+ * @memberof md5
164
+ * @description Create and update Md5 object
165
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
166
+ * @returns {Md5} Md5 object.
167
+ * @example
168
+ * var hash = md5.update('The quick brown fox jumps over the lazy dog');
169
+ * // equal to
170
+ * var hash = md5.create();
171
+ * hash.update('The quick brown fox jumps over the lazy dog');
172
+ */
173
+ var createMethod = function () {
174
+ var method = createOutputMethod('hex');
175
+ method.create = function () {
176
+ return new Md5();
177
+ };
178
+ method.update = function (message) {
179
+ return method.create().update(message);
180
+ };
181
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
182
+ var type = OUTPUT_TYPES[i];
183
+ method[type] = createOutputMethod(type);
184
+ }
185
+ return method;
186
+ };
187
+
188
+ /**
189
+ * @namespace md5.hmac
190
+ */
191
+ /**
192
+ * @method hex
193
+ * @memberof md5.hmac
194
+ * @description Output hash as hex string
195
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
196
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
197
+ * @returns {String} Hex string
198
+ * @example
199
+ * md5.hmac.hex('key', 'The quick brown fox jumps over the lazy dog');
200
+ * // equal to
201
+ * md5.hmac('key', 'The quick brown fox jumps over the lazy dog');
202
+ */
203
+
204
+ /**
205
+ * @method digest
206
+ * @memberof md5.hmac
207
+ * @description Output hash as bytes array
208
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
209
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
210
+ * @returns {Array} Bytes array
211
+ * @example
212
+ * md5.hmac.digest('key', 'The quick brown fox jumps over the lazy dog');
213
+ */
214
+ /**
215
+ * @method array
216
+ * @memberof md5.hmac
217
+ * @description Output hash as bytes array
218
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
219
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
220
+ * @returns {Array} Bytes array
221
+ * @example
222
+ * md5.hmac.array('key', 'The quick brown fox jumps over the lazy dog');
223
+ */
224
+ /**
225
+ * @method arrayBuffer
226
+ * @memberof md5.hmac
227
+ * @description Output hash as ArrayBuffer
228
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
229
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
230
+ * @returns {ArrayBuffer} ArrayBuffer
231
+ * @example
232
+ * md5.hmac.arrayBuffer('key', 'The quick brown fox jumps over the lazy dog');
233
+ */
234
+ /**
235
+ * @method buffer
236
+ * @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
237
+ * @memberof md5.hmac
238
+ * @description Output hash as ArrayBuffer
239
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
240
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
241
+ * @returns {ArrayBuffer} ArrayBuffer
242
+ * @example
243
+ * md5.hmac.buffer('key', 'The quick brown fox jumps over the lazy dog');
244
+ */
245
+ /**
246
+ * @method base64
247
+ * @memberof md5.hmac
248
+ * @description Output hash as base64 string
249
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
250
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
251
+ * @returns {String} base64 string
252
+ * @example
253
+ * md5.hmac.base64('key', 'The quick brown fox jumps over the lazy dog');
254
+ */
255
+ var createHmacOutputMethod = function (outputType) {
256
+ return function (key, message) {
257
+ return new HmacMd5(key, true).update(message)[outputType]();
258
+ };
259
+ };
260
+
261
+ /**
262
+ * @method create
263
+ * @memberof md5.hmac
264
+ * @description Create HmacMd5 object
265
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
266
+ * @returns {HmacMd5} HmacMd5 object.
267
+ * @example
268
+ * var hash = md5.hmac.create('key');
269
+ */
270
+ /**
271
+ * @method update
272
+ * @memberof md5.hmac
273
+ * @description Create and update HmacMd5 object
274
+ * @param {String|Array|Uint8Array|ArrayBuffer} key key
275
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
276
+ * @returns {HmacMd5} HmacMd5 object.
277
+ * @example
278
+ * var hash = md5.hmac.update('key', 'The quick brown fox jumps over the lazy dog');
279
+ * // equal to
280
+ * var hash = md5.hmac.create('key');
281
+ * hash.update('The quick brown fox jumps over the lazy dog');
282
+ */
283
+ var createHmacMethod = function () {
284
+ var method = createHmacOutputMethod('hex');
285
+ method.create = function (key) {
286
+ return new HmacMd5(key);
287
+ };
288
+ method.update = function (key, message) {
289
+ return method.create(key).update(message);
290
+ };
291
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
292
+ var type = OUTPUT_TYPES[i];
293
+ method[type] = createHmacOutputMethod(type);
294
+ }
295
+ return method;
296
+ };
297
+
298
+ /**
299
+ * Md5 class
300
+ * @class Md5
301
+ * @description This is internal class.
302
+ * @see {@link md5.create}
303
+ */
304
+ function Md5(sharedMemory) {
305
+ if (sharedMemory) {
306
+ blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] =
307
+ blocks[4] = blocks[5] = blocks[6] = blocks[7] =
308
+ blocks[8] = blocks[9] = blocks[10] = blocks[11] =
309
+ blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
310
+ this.blocks = blocks;
311
+ this.buffer8 = buffer8;
312
+ } else {
313
+ if (ARRAY_BUFFER) {
314
+ var buffer = new ArrayBuffer(68);
315
+ this.buffer8 = new Uint8Array(buffer);
316
+ this.blocks = new Uint32Array(buffer);
317
+ } else {
318
+ this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
319
+ }
320
+ }
321
+ this.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = this.hBytes = 0;
322
+ this.finalized = this.hashed = false;
323
+ this.first = true;
324
+ }
325
+
326
+ /**
327
+ * @method update
328
+ * @memberof Md5
329
+ * @instance
330
+ * @description Update hash
331
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
332
+ * @returns {Md5} Md5 object.
333
+ * @see {@link md5.update}
334
+ */
335
+ Md5.prototype.update = function (message) {
336
+ if (this.finalized) {
337
+ throw new Error(FINALIZE_ERROR);
338
+ }
339
+
340
+ var result = formatMessage(message);
341
+ message = result[0];
342
+ var isString = result[1];
343
+ var code, index = 0, i, length = message.length, blocks = this.blocks;
344
+ var buffer8 = this.buffer8;
345
+
346
+ while (index < length) {
347
+ if (this.hashed) {
348
+ this.hashed = false;
349
+ blocks[0] = blocks[16];
350
+ blocks[16] = blocks[1] = blocks[2] = blocks[3] =
351
+ blocks[4] = blocks[5] = blocks[6] = blocks[7] =
352
+ blocks[8] = blocks[9] = blocks[10] = blocks[11] =
353
+ blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
354
+ }
355
+
356
+ if (isString) {
357
+ if (ARRAY_BUFFER) {
358
+ for (i = this.start; index < length && i < 64; ++index) {
359
+ code = message.charCodeAt(index);
360
+ if (code < 0x80) {
361
+ buffer8[i++] = code;
362
+ } else if (code < 0x800) {
363
+ buffer8[i++] = 0xc0 | (code >>> 6);
364
+ buffer8[i++] = 0x80 | (code & 0x3f);
365
+ } else if (code < 0xd800 || code >= 0xe000) {
366
+ buffer8[i++] = 0xe0 | (code >>> 12);
367
+ buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
368
+ buffer8[i++] = 0x80 | (code & 0x3f);
369
+ } else {
370
+ code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
371
+ buffer8[i++] = 0xf0 | (code >>> 18);
372
+ buffer8[i++] = 0x80 | ((code >>> 12) & 0x3f);
373
+ buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
374
+ buffer8[i++] = 0x80 | (code & 0x3f);
375
+ }
376
+ }
377
+ } else {
378
+ for (i = this.start; index < length && i < 64; ++index) {
379
+ code = message.charCodeAt(index);
380
+ if (code < 0x80) {
381
+ blocks[i >>> 2] |= code << SHIFT[i++ & 3];
382
+ } else if (code < 0x800) {
383
+ blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3];
384
+ blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
385
+ } else if (code < 0xd800 || code >= 0xe000) {
386
+ blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3];
387
+ blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
388
+ blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
389
+ } else {
390
+ code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
391
+ blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3];
392
+ blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3];
393
+ blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
394
+ blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
395
+ }
396
+ }
397
+ }
398
+ } else {
399
+ if (ARRAY_BUFFER) {
400
+ for (i = this.start; index < length && i < 64; ++index) {
401
+ buffer8[i++] = message[index];
402
+ }
403
+ } else {
404
+ for (i = this.start; index < length && i < 64; ++index) {
405
+ blocks[i >>> 2] |= message[index] << SHIFT[i++ & 3];
406
+ }
407
+ }
408
+ }
409
+ this.lastByteIndex = i;
410
+ this.bytes += i - this.start;
411
+ if (i >= 64) {
412
+ this.start = i - 64;
413
+ this.hash();
414
+ this.hashed = true;
415
+ } else {
416
+ this.start = i;
417
+ }
418
+ }
419
+ if (this.bytes > 4294967295) {
420
+ this.hBytes += this.bytes / 4294967296 << 0;
421
+ this.bytes = this.bytes % 4294967296;
422
+ }
423
+ return this;
424
+ };
425
+
426
+ Md5.prototype.finalize = function () {
427
+ if (this.finalized) {
428
+ return;
429
+ }
430
+ this.finalized = true;
431
+ var blocks = this.blocks, i = this.lastByteIndex;
432
+ blocks[i >>> 2] |= EXTRA[i & 3];
433
+ if (i >= 56) {
434
+ if (!this.hashed) {
435
+ this.hash();
436
+ }
437
+ blocks[0] = blocks[16];
438
+ blocks[16] = blocks[1] = blocks[2] = blocks[3] =
439
+ blocks[4] = blocks[5] = blocks[6] = blocks[7] =
440
+ blocks[8] = blocks[9] = blocks[10] = blocks[11] =
441
+ blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
442
+ }
443
+ blocks[14] = this.bytes << 3;
444
+ blocks[15] = this.hBytes << 3 | this.bytes >>> 29;
445
+ this.hash();
446
+ };
447
+
448
+ Md5.prototype.hash = function () {
449
+ var a, b, c, d, bc, da, blocks = this.blocks;
450
+
451
+ if (this.first) {
452
+ a = blocks[0] - 680876937;
453
+ a = (a << 7 | a >>> 25) - 271733879 << 0;
454
+ d = (-1732584194 ^ a & 2004318071) + blocks[1] - 117830708;
455
+ d = (d << 12 | d >>> 20) + a << 0;
456
+ c = (-271733879 ^ (d & (a ^ -271733879))) + blocks[2] - 1126478375;
457
+ c = (c << 17 | c >>> 15) + d << 0;
458
+ b = (a ^ (c & (d ^ a))) + blocks[3] - 1316259209;
459
+ b = (b << 22 | b >>> 10) + c << 0;
460
+ } else {
461
+ a = this.h0;
462
+ b = this.h1;
463
+ c = this.h2;
464
+ d = this.h3;
465
+ a += (d ^ (b & (c ^ d))) + blocks[0] - 680876936;
466
+ a = (a << 7 | a >>> 25) + b << 0;
467
+ d += (c ^ (a & (b ^ c))) + blocks[1] - 389564586;
468
+ d = (d << 12 | d >>> 20) + a << 0;
469
+ c += (b ^ (d & (a ^ b))) + blocks[2] + 606105819;
470
+ c = (c << 17 | c >>> 15) + d << 0;
471
+ b += (a ^ (c & (d ^ a))) + blocks[3] - 1044525330;
472
+ b = (b << 22 | b >>> 10) + c << 0;
473
+ }
474
+
475
+ a += (d ^ (b & (c ^ d))) + blocks[4] - 176418897;
476
+ a = (a << 7 | a >>> 25) + b << 0;
477
+ d += (c ^ (a & (b ^ c))) + blocks[5] + 1200080426;
478
+ d = (d << 12 | d >>> 20) + a << 0;
479
+ c += (b ^ (d & (a ^ b))) + blocks[6] - 1473231341;
480
+ c = (c << 17 | c >>> 15) + d << 0;
481
+ b += (a ^ (c & (d ^ a))) + blocks[7] - 45705983;
482
+ b = (b << 22 | b >>> 10) + c << 0;
483
+ a += (d ^ (b & (c ^ d))) + blocks[8] + 1770035416;
484
+ a = (a << 7 | a >>> 25) + b << 0;
485
+ d += (c ^ (a & (b ^ c))) + blocks[9] - 1958414417;
486
+ d = (d << 12 | d >>> 20) + a << 0;
487
+ c += (b ^ (d & (a ^ b))) + blocks[10] - 42063;
488
+ c = (c << 17 | c >>> 15) + d << 0;
489
+ b += (a ^ (c & (d ^ a))) + blocks[11] - 1990404162;
490
+ b = (b << 22 | b >>> 10) + c << 0;
491
+ a += (d ^ (b & (c ^ d))) + blocks[12] + 1804603682;
492
+ a = (a << 7 | a >>> 25) + b << 0;
493
+ d += (c ^ (a & (b ^ c))) + blocks[13] - 40341101;
494
+ d = (d << 12 | d >>> 20) + a << 0;
495
+ c += (b ^ (d & (a ^ b))) + blocks[14] - 1502002290;
496
+ c = (c << 17 | c >>> 15) + d << 0;
497
+ b += (a ^ (c & (d ^ a))) + blocks[15] + 1236535329;
498
+ b = (b << 22 | b >>> 10) + c << 0;
499
+ a += (c ^ (d & (b ^ c))) + blocks[1] - 165796510;
500
+ a = (a << 5 | a >>> 27) + b << 0;
501
+ d += (b ^ (c & (a ^ b))) + blocks[6] - 1069501632;
502
+ d = (d << 9 | d >>> 23) + a << 0;
503
+ c += (a ^ (b & (d ^ a))) + blocks[11] + 643717713;
504
+ c = (c << 14 | c >>> 18) + d << 0;
505
+ b += (d ^ (a & (c ^ d))) + blocks[0] - 373897302;
506
+ b = (b << 20 | b >>> 12) + c << 0;
507
+ a += (c ^ (d & (b ^ c))) + blocks[5] - 701558691;
508
+ a = (a << 5 | a >>> 27) + b << 0;
509
+ d += (b ^ (c & (a ^ b))) + blocks[10] + 38016083;
510
+ d = (d << 9 | d >>> 23) + a << 0;
511
+ c += (a ^ (b & (d ^ a))) + blocks[15] - 660478335;
512
+ c = (c << 14 | c >>> 18) + d << 0;
513
+ b += (d ^ (a & (c ^ d))) + blocks[4] - 405537848;
514
+ b = (b << 20 | b >>> 12) + c << 0;
515
+ a += (c ^ (d & (b ^ c))) + blocks[9] + 568446438;
516
+ a = (a << 5 | a >>> 27) + b << 0;
517
+ d += (b ^ (c & (a ^ b))) + blocks[14] - 1019803690;
518
+ d = (d << 9 | d >>> 23) + a << 0;
519
+ c += (a ^ (b & (d ^ a))) + blocks[3] - 187363961;
520
+ c = (c << 14 | c >>> 18) + d << 0;
521
+ b += (d ^ (a & (c ^ d))) + blocks[8] + 1163531501;
522
+ b = (b << 20 | b >>> 12) + c << 0;
523
+ a += (c ^ (d & (b ^ c))) + blocks[13] - 1444681467;
524
+ a = (a << 5 | a >>> 27) + b << 0;
525
+ d += (b ^ (c & (a ^ b))) + blocks[2] - 51403784;
526
+ d = (d << 9 | d >>> 23) + a << 0;
527
+ c += (a ^ (b & (d ^ a))) + blocks[7] + 1735328473;
528
+ c = (c << 14 | c >>> 18) + d << 0;
529
+ b += (d ^ (a & (c ^ d))) + blocks[12] - 1926607734;
530
+ b = (b << 20 | b >>> 12) + c << 0;
531
+ bc = b ^ c;
532
+ a += (bc ^ d) + blocks[5] - 378558;
533
+ a = (a << 4 | a >>> 28) + b << 0;
534
+ d += (bc ^ a) + blocks[8] - 2022574463;
535
+ d = (d << 11 | d >>> 21) + a << 0;
536
+ da = d ^ a;
537
+ c += (da ^ b) + blocks[11] + 1839030562;
538
+ c = (c << 16 | c >>> 16) + d << 0;
539
+ b += (da ^ c) + blocks[14] - 35309556;
540
+ b = (b << 23 | b >>> 9) + c << 0;
541
+ bc = b ^ c;
542
+ a += (bc ^ d) + blocks[1] - 1530992060;
543
+ a = (a << 4 | a >>> 28) + b << 0;
544
+ d += (bc ^ a) + blocks[4] + 1272893353;
545
+ d = (d << 11 | d >>> 21) + a << 0;
546
+ da = d ^ a;
547
+ c += (da ^ b) + blocks[7] - 155497632;
548
+ c = (c << 16 | c >>> 16) + d << 0;
549
+ b += (da ^ c) + blocks[10] - 1094730640;
550
+ b = (b << 23 | b >>> 9) + c << 0;
551
+ bc = b ^ c;
552
+ a += (bc ^ d) + blocks[13] + 681279174;
553
+ a = (a << 4 | a >>> 28) + b << 0;
554
+ d += (bc ^ a) + blocks[0] - 358537222;
555
+ d = (d << 11 | d >>> 21) + a << 0;
556
+ da = d ^ a;
557
+ c += (da ^ b) + blocks[3] - 722521979;
558
+ c = (c << 16 | c >>> 16) + d << 0;
559
+ b += (da ^ c) + blocks[6] + 76029189;
560
+ b = (b << 23 | b >>> 9) + c << 0;
561
+ bc = b ^ c;
562
+ a += (bc ^ d) + blocks[9] - 640364487;
563
+ a = (a << 4 | a >>> 28) + b << 0;
564
+ d += (bc ^ a) + blocks[12] - 421815835;
565
+ d = (d << 11 | d >>> 21) + a << 0;
566
+ da = d ^ a;
567
+ c += (da ^ b) + blocks[15] + 530742520;
568
+ c = (c << 16 | c >>> 16) + d << 0;
569
+ b += (da ^ c) + blocks[2] - 995338651;
570
+ b = (b << 23 | b >>> 9) + c << 0;
571
+ a += (c ^ (b | ~d)) + blocks[0] - 198630844;
572
+ a = (a << 6 | a >>> 26) + b << 0;
573
+ d += (b ^ (a | ~c)) + blocks[7] + 1126891415;
574
+ d = (d << 10 | d >>> 22) + a << 0;
575
+ c += (a ^ (d | ~b)) + blocks[14] - 1416354905;
576
+ c = (c << 15 | c >>> 17) + d << 0;
577
+ b += (d ^ (c | ~a)) + blocks[5] - 57434055;
578
+ b = (b << 21 | b >>> 11) + c << 0;
579
+ a += (c ^ (b | ~d)) + blocks[12] + 1700485571;
580
+ a = (a << 6 | a >>> 26) + b << 0;
581
+ d += (b ^ (a | ~c)) + blocks[3] - 1894986606;
582
+ d = (d << 10 | d >>> 22) + a << 0;
583
+ c += (a ^ (d | ~b)) + blocks[10] - 1051523;
584
+ c = (c << 15 | c >>> 17) + d << 0;
585
+ b += (d ^ (c | ~a)) + blocks[1] - 2054922799;
586
+ b = (b << 21 | b >>> 11) + c << 0;
587
+ a += (c ^ (b | ~d)) + blocks[8] + 1873313359;
588
+ a = (a << 6 | a >>> 26) + b << 0;
589
+ d += (b ^ (a | ~c)) + blocks[15] - 30611744;
590
+ d = (d << 10 | d >>> 22) + a << 0;
591
+ c += (a ^ (d | ~b)) + blocks[6] - 1560198380;
592
+ c = (c << 15 | c >>> 17) + d << 0;
593
+ b += (d ^ (c | ~a)) + blocks[13] + 1309151649;
594
+ b = (b << 21 | b >>> 11) + c << 0;
595
+ a += (c ^ (b | ~d)) + blocks[4] - 145523070;
596
+ a = (a << 6 | a >>> 26) + b << 0;
597
+ d += (b ^ (a | ~c)) + blocks[11] - 1120210379;
598
+ d = (d << 10 | d >>> 22) + a << 0;
599
+ c += (a ^ (d | ~b)) + blocks[2] + 718787259;
600
+ c = (c << 15 | c >>> 17) + d << 0;
601
+ b += (d ^ (c | ~a)) + blocks[9] - 343485551;
602
+ b = (b << 21 | b >>> 11) + c << 0;
603
+
604
+ if (this.first) {
605
+ this.h0 = a + 1732584193 << 0;
606
+ this.h1 = b - 271733879 << 0;
607
+ this.h2 = c - 1732584194 << 0;
608
+ this.h3 = d + 271733878 << 0;
609
+ this.first = false;
610
+ } else {
611
+ this.h0 = this.h0 + a << 0;
612
+ this.h1 = this.h1 + b << 0;
613
+ this.h2 = this.h2 + c << 0;
614
+ this.h3 = this.h3 + d << 0;
615
+ }
616
+ };
617
+
618
+ /**
619
+ * @method hex
620
+ * @memberof Md5
621
+ * @instance
622
+ * @description Output hash as hex string
623
+ * @returns {String} Hex string
624
+ * @see {@link md5.hex}
625
+ * @example
626
+ * hash.hex();
627
+ */
628
+ Md5.prototype.hex = function () {
629
+ this.finalize();
630
+
631
+ var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
632
+
633
+ return HEX_CHARS[(h0 >>> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
634
+ HEX_CHARS[(h0 >>> 12) & 0x0F] + HEX_CHARS[(h0 >>> 8) & 0x0F] +
635
+ HEX_CHARS[(h0 >>> 20) & 0x0F] + HEX_CHARS[(h0 >>> 16) & 0x0F] +
636
+ HEX_CHARS[(h0 >>> 28) & 0x0F] + HEX_CHARS[(h0 >>> 24) & 0x0F] +
637
+ HEX_CHARS[(h1 >>> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
638
+ HEX_CHARS[(h1 >>> 12) & 0x0F] + HEX_CHARS[(h1 >>> 8) & 0x0F] +
639
+ HEX_CHARS[(h1 >>> 20) & 0x0F] + HEX_CHARS[(h1 >>> 16) & 0x0F] +
640
+ HEX_CHARS[(h1 >>> 28) & 0x0F] + HEX_CHARS[(h1 >>> 24) & 0x0F] +
641
+ HEX_CHARS[(h2 >>> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
642
+ HEX_CHARS[(h2 >>> 12) & 0x0F] + HEX_CHARS[(h2 >>> 8) & 0x0F] +
643
+ HEX_CHARS[(h2 >>> 20) & 0x0F] + HEX_CHARS[(h2 >>> 16) & 0x0F] +
644
+ HEX_CHARS[(h2 >>> 28) & 0x0F] + HEX_CHARS[(h2 >>> 24) & 0x0F] +
645
+ HEX_CHARS[(h3 >>> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
646
+ HEX_CHARS[(h3 >>> 12) & 0x0F] + HEX_CHARS[(h3 >>> 8) & 0x0F] +
647
+ HEX_CHARS[(h3 >>> 20) & 0x0F] + HEX_CHARS[(h3 >>> 16) & 0x0F] +
648
+ HEX_CHARS[(h3 >>> 28) & 0x0F] + HEX_CHARS[(h3 >>> 24) & 0x0F];
649
+ };
650
+
651
+ /**
652
+ * @method toString
653
+ * @memberof Md5
654
+ * @instance
655
+ * @description Output hash as hex string
656
+ * @returns {String} Hex string
657
+ * @see {@link md5.hex}
658
+ * @example
659
+ * hash.toString();
660
+ */
661
+ Md5.prototype.toString = Md5.prototype.hex;
662
+
663
+ /**
664
+ * @method digest
665
+ * @memberof Md5
666
+ * @instance
667
+ * @description Output hash as bytes array
668
+ * @returns {Array} Bytes array
669
+ * @see {@link md5.digest}
670
+ * @example
671
+ * hash.digest();
672
+ */
673
+ Md5.prototype.digest = function () {
674
+ this.finalize();
675
+
676
+ var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
677
+ return [
678
+ h0 & 0xFF, (h0 >>> 8) & 0xFF, (h0 >>> 16) & 0xFF, (h0 >>> 24) & 0xFF,
679
+ h1 & 0xFF, (h1 >>> 8) & 0xFF, (h1 >>> 16) & 0xFF, (h1 >>> 24) & 0xFF,
680
+ h2 & 0xFF, (h2 >>> 8) & 0xFF, (h2 >>> 16) & 0xFF, (h2 >>> 24) & 0xFF,
681
+ h3 & 0xFF, (h3 >>> 8) & 0xFF, (h3 >>> 16) & 0xFF, (h3 >>> 24) & 0xFF
682
+ ];
683
+ };
684
+
685
+ /**
686
+ * @method array
687
+ * @memberof Md5
688
+ * @instance
689
+ * @description Output hash as bytes array
690
+ * @returns {Array} Bytes array
691
+ * @see {@link md5.array}
692
+ * @example
693
+ * hash.array();
694
+ */
695
+ Md5.prototype.array = Md5.prototype.digest;
696
+
697
+ /**
698
+ * @method arrayBuffer
699
+ * @memberof Md5
700
+ * @instance
701
+ * @description Output hash as ArrayBuffer
702
+ * @returns {ArrayBuffer} ArrayBuffer
703
+ * @see {@link md5.arrayBuffer}
704
+ * @example
705
+ * hash.arrayBuffer();
706
+ */
707
+ Md5.prototype.arrayBuffer = function () {
708
+ this.finalize();
709
+
710
+ var buffer = new ArrayBuffer(16);
711
+ var blocks = new Uint32Array(buffer);
712
+ blocks[0] = this.h0;
713
+ blocks[1] = this.h1;
714
+ blocks[2] = this.h2;
715
+ blocks[3] = this.h3;
716
+ return buffer;
717
+ };
718
+
719
+ /**
720
+ * @method buffer
721
+ * @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
722
+ * @memberof Md5
723
+ * @instance
724
+ * @description Output hash as ArrayBuffer
725
+ * @returns {ArrayBuffer} ArrayBuffer
726
+ * @see {@link md5.buffer}
727
+ * @example
728
+ * hash.buffer();
729
+ */
730
+ /* istanbul ignore else */
731
+ {
732
+ Md5.prototype.buffer = Md5.prototype.arrayBuffer;
733
+ }
734
+
735
+ /**
736
+ * @method base64
737
+ * @memberof Md5
738
+ * @instance
739
+ * @description Output hash as base64 string
740
+ * @returns {String} base64 string
741
+ * @see {@link md5.base64}
742
+ * @example
743
+ * hash.base64();
744
+ */
745
+ /* istanbul ignore else */
746
+ {
747
+ Md5.prototype.base64 = function () {
748
+ var v1, v2, v3, base64Str = '', bytes = this.array();
749
+ for (var i = 0; i < 15;) {
750
+ v1 = bytes[i++];
751
+ v2 = bytes[i++];
752
+ v3 = bytes[i++];
753
+ base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
754
+ BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] +
755
+ BASE64_ENCODE_CHAR[(v2 << 2 | v3 >>> 6) & 63] +
756
+ BASE64_ENCODE_CHAR[v3 & 63];
757
+ }
758
+ v1 = bytes[i];
759
+ base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
760
+ BASE64_ENCODE_CHAR[(v1 << 4) & 63] +
761
+ '==';
762
+ return base64Str;
763
+ };
764
+ }
765
+
766
+ /**
767
+ * HmacMd5 class
768
+ * @class HmacMd5
769
+ * @extends Md5
770
+ * @description This is internal class.
771
+ * @see {@link md5.hmac.create}
772
+ */
773
+ function HmacMd5(key, sharedMemory) {
774
+ var i, result = formatMessage(key);
775
+ key = result[0];
776
+ if (result[1]) {
777
+ var bytes = [], length = key.length, index = 0, code;
778
+ for (i = 0; i < length; ++i) {
779
+ code = key.charCodeAt(i);
780
+ if (code < 0x80) {
781
+ bytes[index++] = code;
782
+ } else if (code < 0x800) {
783
+ bytes[index++] = (0xc0 | (code >>> 6));
784
+ bytes[index++] = (0x80 | (code & 0x3f));
785
+ } else if (code < 0xd800 || code >= 0xe000) {
786
+ bytes[index++] = (0xe0 | (code >>> 12));
787
+ bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
788
+ bytes[index++] = (0x80 | (code & 0x3f));
789
+ } else {
790
+ code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff));
791
+ bytes[index++] = (0xf0 | (code >>> 18));
792
+ bytes[index++] = (0x80 | ((code >>> 12) & 0x3f));
793
+ bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
794
+ bytes[index++] = (0x80 | (code & 0x3f));
795
+ }
796
+ }
797
+ key = bytes;
798
+ }
799
+
800
+ if (key.length > 64) {
801
+ key = (new Md5(true)).update(key).array();
802
+ }
803
+
804
+ var oKeyPad = [], iKeyPad = [];
805
+ for (i = 0; i < 64; ++i) {
806
+ var b = key[i] || 0;
807
+ oKeyPad[i] = 0x5c ^ b;
808
+ iKeyPad[i] = 0x36 ^ b;
809
+ }
810
+
811
+ Md5.call(this, sharedMemory);
812
+
813
+ this.update(iKeyPad);
814
+ this.oKeyPad = oKeyPad;
815
+ this.inner = true;
816
+ this.sharedMemory = sharedMemory;
817
+ }
818
+ /* istanbul ignore else */
819
+ {
820
+ HmacMd5.prototype = new Md5();
821
+
822
+ HmacMd5.prototype.finalize = function () {
823
+ Md5.prototype.finalize.call(this);
824
+ if (this.inner) {
825
+ this.inner = false;
826
+ var innerHash = this.array();
827
+ Md5.call(this, this.sharedMemory);
828
+ this.update(this.oKeyPad);
829
+ this.update(innerHash);
830
+ Md5.prototype.finalize.call(this);
831
+ }
832
+ };
833
+ }
834
+
835
+ var exports = createMethod();
836
+ exports.md5 = exports;
837
+ /* istanbul ignore else */
838
+ {
839
+ exports.md5.hmac = createHmacMethod();
840
+ }
841
+
842
+ if (COMMON_JS) {
843
+ module.exports = exports;
844
+ } else {
845
+ /**
846
+ * @method md5
847
+ * @description Md5 hash function, export to global in browsers.
848
+ * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
849
+ * @returns {String} md5 hashes
850
+ * @example
851
+ * md5(''); // d41d8cd98f00b204e9800998ecf8427e
852
+ * md5('The quick brown fox jumps over the lazy dog'); // 9e107d9d372bb6826bd81d3542a419d6
853
+ * md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0
854
+ *
855
+ * // It also supports UTF-8 encoding
856
+ * md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07
857
+ *
858
+ * // It also supports byte `Array`, `Uint8Array`, `ArrayBuffer`
859
+ * md5([]); // d41d8cd98f00b204e9800998ecf8427e
860
+ * md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e
861
+ */
862
+ root.md5 = exports;
863
+ }
864
+ })();
865
+ } (md5$1));
866
+
867
+ var md5Exports = md5$1.exports;
868
+ var md5 = /*@__PURE__*/getDefaultExportFromCjs(md5Exports);
869
+
870
+ export { md5 as default, md5 };