mirror of
https://github.com/emn178/js-md5.git
synced 2026-11-18 16:08:52 +08:00
### Fixed
- Incorrect hash for `DataView` input. - Throws `ArrayBuffer is not defined` in browsers without `ArrayBuffer`. ### Changed - Multi-byte typed arrays such as `Uint16Array`, `Uint32Array` and `Float32Array` are now hashed by their underlying bytes, the same as Node.js `crypto` and Web Crypto. Previously each element was treated as one byte. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c2a7870840
commit
66db5dbd99
+9
-9
@@ -93,7 +93,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line815">line 815</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line821">line 821</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -224,7 +224,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line734">line 734</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line740">line 740</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -351,7 +351,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line746">line 746</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line752">line 752</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -478,7 +478,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line784">line 784</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line790">line 790</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -607,7 +607,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line768">line 768</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line774">line 774</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -734,7 +734,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line712">line 712</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line718">line 718</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -861,7 +861,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line667">line 667</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line673">line 673</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -988,7 +988,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line700">line 700</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line706">line 706</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -1173,7 +1173,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line363">line 363</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line369">line 369</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
+9
-9
@@ -47,7 +47,7 @@
|
||||
|
||||
|
||||
<dt class="tag-version">Version:</dt>
|
||||
<dd class="tag-version"><ul class="dummy"><li>0.10.0</li></ul></dd>
|
||||
<dd class="tag-version"><ul class="dummy"><li>0.11.0</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line115">line 115</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line119">line 119</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -417,7 +417,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line124">line 124</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line128">line 128</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -590,7 +590,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line143">line 143</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line147">line 147</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -765,7 +765,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line133">line 133</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line137">line 137</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -880,7 +880,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line158">line 158</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line162">line 162</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -1053,7 +1053,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line106">line 106</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line110">line 110</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -1226,7 +1226,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line95">line 95</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line99">line 99</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -1401,7 +1401,7 @@ md5('The quick brown fox jumps over the lazy dog');</code></pre>
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line166">line 166</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line170">line 170</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -214,7 +214,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line900">line 900</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line906">line 906</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -115,7 +115,7 @@ APIs, including <code>hex</code>, <code>array</code>, <code>digest</code>, and <
|
||||
<li><a href="https://jsperf.app/jonuhi/9">Async Benchmark (jsperf.app)</a></li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li>js-md5 is the fastest synchronous MD5 library, but slower than Hash-WASM</li>
|
||||
<li>js-md5 is the fastest for short strings in these benchmarks. For large data, WebAssembly-based libraries (e.g. Hash-WASM) are faster.</li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a href="https://github.com/emn178/js-md5/issues/19">File Benchmark - Issue #19</a></li>
|
||||
@@ -167,7 +167,7 @@ md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffad
|
||||
// It also supports UTF-8 encoding
|
||||
md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07
|
||||
|
||||
// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer`
|
||||
// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` and other `ArrayBuffer` views (their underlying bytes are hashed)
|
||||
md5([]); // d41d8cd98f00b204e9800998ecf8427e
|
||||
md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e
|
||||
|
||||
|
||||
+9
-9
@@ -71,7 +71,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line225">line 225</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line231">line 231</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line251">line 251</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line257">line 257</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -457,7 +457,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line261">line 261</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line267">line 267</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -662,7 +662,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line282">line 282</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line288">line 288</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -869,7 +869,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line271">line 271</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line277">line 277</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -1042,7 +1042,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line298">line 298</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line304">line 304</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -1247,7 +1247,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line241">line 241</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line247">line 247</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -1452,7 +1452,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line228">line 228</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line234">line 234</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -1659,7 +1659,7 @@ md5.hmac('key', 'The quick brown fox jumps over the lazy dog');</code></pre>
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line307">line 307</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line313">line 313</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
+9
-9
@@ -93,7 +93,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line335">line 335</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line341">line 341</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -208,7 +208,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line734">line 734</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line740">line 740</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -330,7 +330,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line746">line 746</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line752">line 752</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -452,7 +452,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line784">line 784</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line790">line 790</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -576,7 +576,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line768">line 768</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line774">line 774</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -698,7 +698,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line712">line 712</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line718">line 718</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -820,7 +820,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line667">line 667</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line673">line 673</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -942,7 +942,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line700">line 700</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line706">line 706</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -1122,7 +1122,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line363">line 363</a>
|
||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line369">line 369</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
+11
-5
@@ -30,7 +30,7 @@
|
||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||
*
|
||||
* @namespace md5
|
||||
* @version 0.10.0
|
||||
* @version 0.11.0
|
||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||
* @copyright Chen, Yi-Cyuan 2014-2026
|
||||
* @license MIT
|
||||
@@ -94,7 +94,7 @@
|
||||
};
|
||||
}
|
||||
|
||||
var isView = ArrayBuffer.isView;
|
||||
var isView = ARRAY_BUFFER ? ArrayBuffer.isView : null;
|
||||
/* istanbul ignore else */
|
||||
if (FEATURE_LEGACY && ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
|
||||
isView = function (obj) {
|
||||
@@ -114,11 +114,15 @@
|
||||
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
||||
return [new Uint8Array(message), false];
|
||||
}
|
||||
if (!isArray(message) && !isView(message)) {
|
||||
if (isArray(message)) {
|
||||
return [message, false];
|
||||
}
|
||||
if (!ARRAY_BUFFER || !isView(message)) {
|
||||
throw new Error(INPUT_ERROR);
|
||||
}
|
||||
return [message, false];
|
||||
}
|
||||
// read the underlying bytes of any view (DataView, Uint16Array, ...)
|
||||
return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
|
||||
};
|
||||
|
||||
/**
|
||||
* @method hex
|
||||
@@ -238,6 +242,8 @@
|
||||
throw new Error(INPUT_ERROR);
|
||||
} else if (message.constructor === ArrayBuffer) {
|
||||
message = new Uint8Array(message);
|
||||
} else if (ARRAY_BUFFER && isView(message) && message.constructor !== Buffer) {
|
||||
message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
|
||||
}
|
||||
}
|
||||
if (isArray(message) || isView(message) ||
|
||||
|
||||
Reference in New Issue
Block a user