Compare commits

..

13 Commits

Author SHA1 Message Date
emn178 4c40b94725
Merge pull request #41 from emn178/dependabot/npm_and_yarn/babel/traverse-7.23.2
Bump @babel/traverse from 7.21.2 to 7.23.2
2 years ago
dependabot[bot] 1ed1b0677d
Bump @babel/traverse from 7.21.2 to 7.23.2
Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.21.2 to 7.23.2.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse)

---
updated-dependencies:
- dependency-name: "@babel/traverse"
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2 years ago
Yi-Cyuan Chen 698290b4bc ### Fixed
- package.json main property.
2 years ago
Yi-Cyuan Chen 0ecaeee185 ### Remove
- package.json module property.
2 years ago
Yi-Cyuan Chen daf1188dc6 ### Added
- TypeScript base64 interfaces.
- Disable webpack polyfill.
2 years ago
Yi-Cyuan Chen a9de3df8c6 update 2 years ago
Yi-Cyuan Chen 08049ec6fa update README 2 years ago
Yi-Cyuan Chen bdf1150097 ## v0.8.0 / 2023-09-27
### Added
- TypeScript interfaces.
- HMAC feature.

### Fixed
- deprecated `new Buffer`, replace with `Buffer.from`.
- dependencies and security issues.
- don't modify global Array and ArrayBuffer prototypes.
- refactor: simplify formatMessage internal logic.

### Changed
- remove `eval` and use `require` directly.
- throw error by Error oject.
- throw error if update after finalize
- use unsigned right shift.
2 years ago
emn178 c2e8d8683d
Merge pull request #32 from emn178/dependabot/npm_and_yarn/minimist-and-mkdirp-and-mocha-and-nyc--removed
Bump minimist, mkdirp, mocha and nyc
2 years ago
dependabot[bot] c154bc5a38
Bump minimist, mkdirp, mocha and nyc
Removes [minimist](https://github.com/minimistjs/minimist). It's no longer used after updating ancestor dependencies [minimist](https://github.com/minimistjs/minimist), [mkdirp](https://github.com/isaacs/node-mkdirp), [mocha](https://github.com/mochajs/mocha) and [nyc](https://github.com/istanbuljs/nyc). These dependencies need to be updated together.


Removes `minimist`

Updates `mkdirp` from 0.5.1 to 1.0.4
- [Release notes](https://github.com/isaacs/node-mkdirp/releases)
- [Changelog](https://github.com/isaacs/node-mkdirp/blob/main/CHANGELOG.md)
- [Commits](https://github.com/isaacs/node-mkdirp/compare/0.5.1...v1.0.4)

Updates `mocha` from 2.3.4 to 10.2.0
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mochajs/mocha/compare/2.3.4...v10.2.0)

Updates `nyc` from 11.3.0 to 15.1.0
- [Release notes](https://github.com/istanbuljs/nyc/releases)
- [Changelog](https://github.com/istanbuljs/nyc/blob/master/CHANGELOG.md)
- [Commits](https://github.com/istanbuljs/nyc/compare/v11.3.0...v15.1.0)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
- dependency-name: mkdirp
  dependency-type: indirect
- dependency-name: mocha
  dependency-type: direct:development
- dependency-name: nyc
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2 years ago
Yi-Cyuan Chen 0263ab835f Fixed incorrect result when first bit is 1 of bytes. #18 8 years ago
Yi-Cyuan Chen 5f0bd5a888 Improved performance of hBytes increment. 8 years ago
Yi-Cyuan Chen cb8eb73ef1 Fixed incorrect result when file size >= 4G. 8 years ago

@ -1,2 +0,0 @@
/node_modules/
/tests/

2
.gitignore vendored

@ -1,2 +1,4 @@
/node_modules/
/covreporter/
/.nyc_output/
/coverage/

@ -0,0 +1,9 @@
/node_modules/
/coverage/
/.nyc_output/
/tests/
/doc/
.covignore
.travis.yml
.npmignore
bower.json

@ -4,8 +4,7 @@ node_js:
- "8.6.0"
before_install:
- npm install coveralls
- npm install mocha-lcov-reporter
script: npm run-script coveralls
after_success: npm run coveralls
branches:
only:
- master

@ -1,5 +1,47 @@
# Change Log
## v0.8.3 / 2023-10-09
### Fixed
- package.json main property.
## v0.8.2 / 2023-10-09
### Remove
- package.json module property.
## v0.8.1 / 2023-10-09
### Added
- TypeScript base64 interfaces.
- Disable webpack polyfill.
## v0.8.0 / 2023-09-27
### Added
- TypeScript interfaces.
- HMAC feature.
### Fixed
- deprecated `new Buffer`, replace with `Buffer.from`.
- dependencies and security issues.
- don't modify global Array and ArrayBuffer prototypes.
- refactor: simplify formatMessage internal logic.
### Changed
- remove `eval` and use `require` directly.
- throw error by Error oject.
- throw error if update after finalize
- use unsigned right shift.
## v0.7.3 / 2017-12-18
### Fixed
- incorrect result when first bit is 1 of bytes. #18
## v0.7.2 / 2017-10-31
### Improved
- performance of hBytes increment.
## v0.7.1 / 2017-10-29
### Fixed
- incorrect result when file size >= 4G.
## v0.7.0 / 2017-10-29
### Fixed
- incorrect result when file size >= 512M.

@ -1,4 +1,4 @@
Copyright 2014-2017 Chen, Yi-Cyuan
Copyright 2014-2023 Chen, Yi-Cyuan
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

@ -3,7 +3,7 @@
[![Coverage Status](https://coveralls.io/repos/emn178/js-md5/badge.svg?branch=master)](https://coveralls.io/r/emn178/js-md5?branch=master)
[![NPM](https://nodei.co/npm/js-md5.png?stars&downloads)](https://nodei.co/npm/js-md5/)
A simple MD5 hash function for JavaScript supports UTF-8 encoding.
A simple and fast MD5 hash function for JavaScript supports UTF-8 encoding.
## Demo
[MD5 Online](http://emn178.github.io/online-tools/md5.html)
@ -13,6 +13,10 @@ A simple MD5 hash function for JavaScript supports UTF-8 encoding.
[Compress](https://raw.github.com/emn178/js-md5/master/build/md5.min.js)
[Uncompress](https://raw.github.com/emn178/js-md5/master/src/md5.js)
## Benchmark
[jsPerf Benchmark](https://jsperf.app/jonuhi)
[File Benchmark](https://github.com/emn178/js-md5/issues/19)
## Installation
You can also install js-md5 by using Bower.
@ -32,11 +36,28 @@ md5('Message to hash');
var hash = md5.create();
hash.update('Message to hash');
hash.hex();
// HMAC
md5.hmac('key', 'Message to hash');
var hash = md5.hmac.create('key');
hash.update('Message to hash');
hash.hex();
```
### Node.js
If you use node.js, you should require the module first:
```JavaScript
md5 = require('js-md5');
var md5 = require('js-md5');
```
### TypeScript
If you use TypeScript, you can import like this:
```TypeScript
import { md5 } from 'js-md5';
```
## RequireJS
It supports AMD:
```JavaScript
require(['your/path/md5.js'], function(md5) {
@ -66,10 +87,15 @@ md5.digest(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 24
md5.arrayBuffer(''); // ArrayBuffer
md5.buffer(''); // ArrayBuffer, deprecated, This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
md5.base64(''); // 1B2M2Y8AsgTpgAmY7PhCfg==
// HMAC
md5.hmac.hex('key', 'Message to hash');
md5.hmac.array('key', 'Message to hash');
// ...
```
## License
The project is released under the [MIT license](http://www.opensource.org/licenses/MIT).
The project is released under the [MIT license](https://opensource.org/license/mit/).
## Contact
The project's website is located at https://github.com/emn178/js-md5

@ -1,6 +1,6 @@
{
"name": "js-md5",
"version": "0.7.0",
"version": "0.8.3",
"main": ["src/md5.js"],
"ignore": [
"tests"

6
build/md5.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: Md5</title>
<title>JSDoc: Namespace: md5</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
@ -17,7 +17,7 @@
<div id="main">
<h1 class="page-title">Class: Md5</h1>
<h1 class="page-title">Namespace: md5</h1>
@ -28,7 +28,7 @@
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>Md5<span class="signature">()</span><span class="type-signature"></span></h2>
<h2>md5</h2>
</header>
@ -37,20 +37,20 @@
<div class="container-overview">
<div class="description"><a href="https://github.com/emn178/js-md5">js-md5</a></div>
<h4 class="name" id="Md5"><span class="type-signature"></span>new Md5<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
<dt class="tag-version">Version:</dt>
<dd class="tag-version"><ul class="dummy"><li>0.8.0</li></ul></dd>
<div class="description">
This is internal class.
</div>
@ -64,19 +64,32 @@
<dl class="details">
<dt class="tag-author">Author:</dt>
<dd class="tag-author">
<ul>
<li>Chen, Yi-Cyuan [emn178@gmail.com]</li>
</ul>
</dd>
<dt class="tag-copyright">Copyright:</dt>
<dd class="tag-copyright"><ul class="dummy"><li>Chen, Yi-Cyuan 2014-2023</li></ul></dd>
<dt class="tag-license">License:</dt>
<dd class="tag-license"><ul class="dummy"><li>MIT</li></ul></dd>
<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#line1">line 1</a>
</li></ul></dd>
@ -84,39 +97,36 @@
</dl>
</div>
<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#line178">line 178</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5.html#.create">md5.create</a></li>
</ul>
</dd>
</dl>
<h3 class="subsection-title">Namespaces</h3>
<dl>
<dt><a href="md5.hmac.html">hmac</a></dt>
<dd></dd>
</dl>
<h3 class="subsection-title">Methods</h3>
@ -124,13 +134,16 @@
<h4 class="name" id=".array"><span class="type-signature">(static) </span>array<span class="signature">(message)</span><span class="type-signature"> &rarr; {Array}</span></h4>
</div>
<div class="description">
Output hash as bytes array
</div>
@ -140,40 +153,65 @@
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<h3 class="subsection-title">Methods</h3>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<h4 class="name" id="array"><span class="type-signature"></span>array<span class="signature">()</span><span class="type-signature"> &rarr; {Array}</span></h4>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type">String</span>
|
<div class="description">
Output hash as bytes array
</div>
<span class="param-type">Array</span>
|
<span class="param-type">Uint8Array</span>
|
<span class="param-type">ArrayBuffer</span>
</td>
<td class="description last">message to hash</td>
</tr>
</tbody>
</table>
@ -206,20 +244,13 @@
<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#line575">line 575</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line95">line 95</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5.html#.array">md5.array</a></li>
</ul>
</dd>
</dl>
@ -236,6 +267,8 @@
<h5>Returns:</h5>
@ -264,7 +297,7 @@
<h5>Example</h5>
<pre class="prettyprint"><code>hash.array();</code></pre>
<pre class="prettyprint"><code>md5.array('The quick brown fox jumps over the lazy dog');</code></pre>
@ -274,7 +307,7 @@
<h4 class="name" id="arrayBuffer"><span class="type-signature"></span>arrayBuffer<span class="signature">()</span><span class="type-signature"> &rarr; {ArrayBuffer}</span></h4>
<h4 class="name" id=".arrayBuffer"><span class="type-signature">(static) </span>arrayBuffer<span class="signature">(message)</span><span class="type-signature"> &rarr; {ArrayBuffer}</span></h4>
@ -293,6 +326,64 @@
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type">String</span>
|
<span class="param-type">Array</span>
|
<span class="param-type">Uint8Array</span>
|
<span class="param-type">ArrayBuffer</span>
</td>
<td class="description last">message to hash</td>
</tr>
</tbody>
</table>
@ -326,20 +417,13 @@
<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#line587">line 587</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line104">line 104</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5.html#.arrayBuffer">md5.arrayBuffer</a></li>
</ul>
</dd>
</dl>
@ -356,6 +440,8 @@
<h5>Returns:</h5>
@ -384,7 +470,7 @@
<h5>Example</h5>
<pre class="prettyprint"><code>hash.arrayBuffer();</code></pre>
<pre class="prettyprint"><code>md5.arrayBuffer('The quick brown fox jumps over the lazy dog');</code></pre>
@ -394,7 +480,7 @@
<h4 class="name" id="base64"><span class="type-signature"></span>base64<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
<h4 class="name" id=".base64"><span class="type-signature">(static) </span>base64<span class="signature">(message)</span><span class="type-signature"> &rarr; {String}</span></h4>
@ -413,6 +499,64 @@
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type">String</span>
|
<span class="param-type">Array</span>
|
<span class="param-type">Uint8Array</span>
|
<span class="param-type">ArrayBuffer</span>
</td>
<td class="description last">message to hash</td>
</tr>
</tbody>
</table>
@ -446,20 +590,13 @@
<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#line622">line 622</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line123">line 123</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5.html#.base64">md5.base64</a></li>
</ul>
</dd>
</dl>
@ -476,6 +613,8 @@
<h5>Returns:</h5>
@ -504,7 +643,7 @@
<h5>Example</h5>
<pre class="prettyprint"><code>hash.base64();</code></pre>
<pre class="prettyprint"><code>md5.base64('The quick brown fox jumps over the lazy dog');</code></pre>
@ -514,7 +653,7 @@
<h4 class="name" id="buffer"><span class="type-signature"></span>buffer<span class="signature">()</span><span class="type-signature"> &rarr; {ArrayBuffer}</span></h4>
<h4 class="name" id=".buffer"><span class="type-signature">(static) </span>buffer<span class="signature">(message)</span><span class="type-signature"> &rarr; {ArrayBuffer}</span></h4>
@ -533,6 +672,64 @@
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type">String</span>
|
<span class="param-type">Array</span>
|
<span class="param-type">Uint8Array</span>
|
<span class="param-type">ArrayBuffer</span>
</td>
<td class="description last">message to hash</td>
</tr>
</tbody>
</table>
@ -568,20 +765,13 @@
<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#line609">line 609</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line113">line 113</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5.html#.buffer">md5.buffer</a></li>
</ul>
</dd>
</dl>
@ -598,6 +788,8 @@
<h5>Returns:</h5>
@ -626,7 +818,7 @@
<h5>Example</h5>
<pre class="prettyprint"><code>hash.buffer();</code></pre>
<pre class="prettyprint"><code>md5.buffer('The quick brown fox jumps over the lazy dog');</code></pre>
@ -636,7 +828,7 @@
<h4 class="name" id="digest"><span class="type-signature"></span>digest<span class="signature">()</span><span class="type-signature"> &rarr; {Array}</span></h4>
<h4 class="name" id=".create"><span class="type-signature">(static) </span>create<span class="signature">()</span><span class="type-signature"> &rarr; {<a href="Md5.html">Md5</a>}</span></h4>
@ -644,7 +836,7 @@
<div class="description">
Output hash as bytes array
Create Md5 object
</div>
@ -688,20 +880,13 @@
<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#line553">line 553</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line138">line 138</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5.html#.digest">md5.digest</a></li>
</ul>
</dd>
</dl>
@ -718,11 +903,13 @@
<h5>Returns:</h5>
<div class="param-desc">
Bytes array
Md5 object.
</div>
@ -733,7 +920,7 @@
</dt>
<dd>
<span class="param-type">Array</span>
<span class="param-type"><a href="Md5.html">Md5</a></span>
</dd>
@ -746,7 +933,7 @@
<h5>Example</h5>
<pre class="prettyprint"><code>hash.digest();</code></pre>
<pre class="prettyprint"><code>var hash = md5.create();</code></pre>
@ -756,7 +943,7 @@
<h4 class="name" id="hex"><span class="type-signature"></span>hex<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
<h4 class="name" id=".digest"><span class="type-signature">(static) </span>digest<span class="signature">(message)</span><span class="type-signature"> &rarr; {Array}</span></h4>
@ -764,7 +951,7 @@
<div class="description">
Output hash as hex string
Output hash as bytes array
</div>
@ -775,6 +962,64 @@
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type">String</span>
|
<span class="param-type">Array</span>
|
<span class="param-type">Uint8Array</span>
|
<span class="param-type">ArrayBuffer</span>
</td>
<td class="description last">message to hash</td>
</tr>
</tbody>
</table>
@ -808,20 +1053,13 @@
<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#line508">line 508</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line86">line 86</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5.html#.hex">md5.hex</a></li>
</ul>
</dd>
</dl>
@ -838,11 +1076,13 @@
<h5>Returns:</h5>
<div class="param-desc">
Hex string
Bytes array
</div>
@ -853,7 +1093,7 @@
</dt>
<dd>
<span class="param-type">String</span>
<span class="param-type">Array</span>
</dd>
@ -866,7 +1106,7 @@
<h5>Example</h5>
<pre class="prettyprint"><code>hash.hex();</code></pre>
<pre class="prettyprint"><code>md5.digest('The quick brown fox jumps over the lazy dog');</code></pre>
@ -876,7 +1116,7 @@
<h4 class="name" id="toString"><span class="type-signature"></span>toString<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
<h4 class="name" id=".hex"><span class="type-signature">(static) </span>hex<span class="signature">(message)</span><span class="type-signature"> &rarr; {String}</span></h4>
@ -895,6 +1135,64 @@
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type">String</span>
|
<span class="param-type">Array</span>
|
<span class="param-type">Uint8Array</span>
|
<span class="param-type">ArrayBuffer</span>
</td>
<td class="description last">message to hash</td>
</tr>
</tbody>
</table>
@ -928,20 +1226,13 @@
<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#line541">line 541</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line75">line 75</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5.html#.hex">md5.hex</a></li>
</ul>
</dd>
</dl>
@ -958,6 +1249,8 @@
<h5>Returns:</h5>
@ -986,7 +1279,9 @@
<h5>Example</h5>
<pre class="prettyprint"><code>hash.toString();</code></pre>
<pre class="prettyprint"><code>md5.hex('The quick brown fox jumps over the lazy dog');
// equal to
md5('The quick brown fox jumps over the lazy dog');</code></pre>
@ -996,7 +1291,7 @@
<h4 class="name" id="update"><span class="type-signature"></span>update<span class="signature">(message)</span><span class="type-signature"> &rarr; {<a href="Md5_.html">Md5</a>}</span></h4>
<h4 class="name" id=".update"><span class="type-signature">(static) </span>update<span class="signature">(message)</span><span class="type-signature"> &rarr; {<a href="Md5.html">Md5</a>}</span></h4>
@ -1004,7 +1299,7 @@
<div class="description">
Update hash
Create and update Md5 object
</div>
@ -1106,20 +1401,13 @@
<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#line206">line 206</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line146">line 146</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5.html#.update">md5.update</a></li>
</ul>
</dd>
</dl>
@ -1136,6 +1424,8 @@
<h5>Returns:</h5>
@ -1151,7 +1441,7 @@
</dt>
<dd>
<span class="param-type"><a href="Md5_.html">Md5</a></span>
<span class="param-type"><a href="Md5.html">Md5</a></span>
</dd>
@ -1162,6 +1452,14 @@
<h5>Example</h5>
<pre class="prettyprint"><code>var hash = md5.update('The quick brown fox jumps over the lazy dog');
// equal to
var hash = md5.create();
hash.update('The quick brown fox jumps over the lazy dog');</code></pre>
@ -1179,13 +1477,13 @@
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Md5_.html">Md5</a></li></ul><h3>Namespaces</h3><ul><li><a href="md5.html">md5</a></li></ul><h3>Global</h3><ul><li><a href="global.html#md5%2508">md5</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="md5_.html">md5</a></li><li><a href="md5.hmac.html">hmac</a></li></ul><h3>Classes</h3><ul><li><a href="HmacMd5.html">HmacMd5</a></li><li><a href="Md5.html">Md5</a></li></ul><h3>Global</h3><ul><li><a href="global.html#md5%2508">md5</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Oct 29 2017 20:15:53 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Sep 27 2023 21:32:04 GMT+0800 (台北標準時間)
</footer>
<script> prettyPrint(); </script>

@ -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#line655">line 655</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line852">line 852</a>
</li></ul></dd>
@ -237,6 +237,8 @@
<h5>Returns:</h5>
@ -294,13 +296,13 @@ md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e</code></pre>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Md5_.html">Md5</a></li></ul><h3>Namespaces</h3><ul><li><a href="md5.html">md5</a></li></ul><h3>Global</h3><ul><li><a href="global.html#md5%2508">md5</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="md5_.html">md5</a></li><li><a href="md5.hmac.html">hmac</a></li></ul><h3>Classes</h3><ul><li><a href="HmacMd5.html">HmacMd5</a></li><li><a href="Md5.html">Md5</a></li></ul><h3>Global</h3><ul><li><a href="global.html#md5%2508">md5</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Oct 29 2017 20:15:53 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Sep 27 2023 21:32:04 GMT+0800 (台北標準時間)
</footer>
<script> prettyPrint(); </script>

@ -43,24 +43,53 @@
<section>
<article><h1>js-md5</h1><p><a href="https://travis-ci.org/emn178/js-md5"><img src="https://travis-ci.org/emn178/js-md5.svg?branch=master" alt="Build Status"></a>
<a href="https://coveralls.io/r/emn178/js-md5?branch=master"><img src="https://coveralls.io/repos/emn178/js-md5/badge.svg?branch=master" alt="Coverage Status"></a><br><a href="https://nodei.co/npm/js-md5/"><img src="https://nodei.co/npm/js-md5.png?stars&amp;downloads" alt="NPM"></a></p>
<article><h1>js-md5</h1>
<p><a href="https://travis-ci.org/emn178/js-md5"><img src="https://travis-ci.org/emn178/js-md5.svg?branch=master" alt="Build Status"></a>
<a href="https://coveralls.io/r/emn178/js-md5?branch=master"><img src="https://coveralls.io/repos/emn178/js-md5/badge.svg?branch=master" alt="Coverage Status"></a><br>
<a href="https://nodei.co/npm/js-md5/"><img src="https://nodei.co/npm/js-md5.png?stars&amp;downloads" alt="NPM"></a></p>
<p>A simple MD5 hash function for JavaScript supports UTF-8 encoding.</p>
<h2>Demo</h2><p><a href="http://emn178.github.io/online-tools/md5.html">MD5 Online</a><br><a href="http://emn178.github.io/online-tools/md5_checksum.html">MD5 File Checksum Online</a></p>
<h2>Download</h2><p><a href="https://raw.github.com/emn178/js-md5/master/build/md5.min.js">Compress</a><br><a href="https://raw.github.com/emn178/js-md5/master/src/md5.js">Uncompress</a></p>
<h2>Installation</h2><p>You can also install js-md5 by using Bower.</p>
<pre class="prettyprint source"><code>bower install md5</code></pre><p>For node.js, you can use this command to install:</p>
<pre class="prettyprint source"><code>npm install js-md5</code></pre><h2>Notice</h2><p><code>buffer</code> method is deprecated. This maybe confuse with Buffer in node.js. Please use <code>arrayBuffer</code> instead.</p>
<h2>Usage</h2><p>You could use like this:</p>
<h2>Demo</h2>
<p><a href="http://emn178.github.io/online-tools/md5.html">MD5 Online</a><br>
<a href="http://emn178.github.io/online-tools/md5_checksum.html">MD5 File Checksum Online</a></p>
<h2>Download</h2>
<p><a href="https://raw.github.com/emn178/js-md5/master/build/md5.min.js">Compress</a><br>
<a href="https://raw.github.com/emn178/js-md5/master/src/md5.js">Uncompress</a></p>
<h2>Installation</h2>
<p>You can also install js-md5 by using Bower.</p>
<pre><code>bower install md5
</code></pre>
<p>For node.js, you can use this command to install:</p>
<pre><code>npm install js-md5
</code></pre>
<h2>Notice</h2>
<p><code>buffer</code> method is deprecated. This maybe confuse with Buffer in node.js. Please use <code>arrayBuffer</code> instead.</p>
<h2>Usage</h2>
<p>You could use like this:</p>
<pre class="prettyprint source lang-JavaScript"><code>md5('Message to hash');
var hash = md5.create();
hash.update('Message to hash');
hash.hex();</code></pre><p>If you use node.js, you should require the module first:</p>
<pre class="prettyprint source lang-JavaScript"><code>md5 = require('js-md5');</code></pre><p>It supports AMD:</p>
hash.hex();
// HMAC
md5.hmac('key', 'Message to hash');
var hash = md5.hmac.create('key');
hash.update('Message to hash');
hash.hex();
</code></pre>
<h3>Node.js</h3>
<p>If you use node.js, you should require the module first:</p>
<pre class="prettyprint source lang-JavaScript"><code>var md5 = require('js-md5');
</code></pre>
<h2>RequireJS</h2>
<p>It supports AMD:</p>
<pre class="prettyprint source lang-JavaScript"><code>require(['your/path/md5.js'], function(md5) {
// ...
});</code></pre><p><a href="https://emn178.github.com/js-md5/doc/">See document</a></p>
<h2>Example</h2><pre class="prettyprint source lang-JavaScript"><code>md5(''); // d41d8cd98f00b204e9800998ecf8427e
});
</code></pre>
<p><a href="https://emn178.github.com/js-md5/doc/">See document</a></p>
<h2>Example</h2>
<pre class="prettyprint source lang-JavaScript"><code>md5(''); // d41d8cd98f00b204e9800998ecf8427e
md5('The quick brown fox jumps over the lazy dog'); // 9e107d9d372bb6826bd81d3542a419d6
md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0
@ -78,8 +107,18 @@ md5.array(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248
md5.digest(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126]
md5.arrayBuffer(''); // ArrayBuffer
md5.buffer(''); // ArrayBuffer, deprecated, This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
md5.base64(''); // 1B2M2Y8AsgTpgAmY7PhCfg==</code></pre><h2>License</h2><p>The project is released under the <a href="http://www.opensource.org/licenses/MIT">MIT license</a>.</p>
<h2>Contact</h2><p>The project's website is located at https://github.com/emn178/js-md5<br>Author: Chen, Yi-Cyuan (emn178@gmail.com)</p></article>
md5.base64(''); // 1B2M2Y8AsgTpgAmY7PhCfg==
// HMAC
md5.hmac.hex('key', 'Message to hash');
md5.hmac.array('key', 'Message to hash');
// ...
</code></pre>
<h2>License</h2>
<p>The project is released under the <a href="https://opensource.org/license/mit/">MIT license</a>.</p>
<h2>Contact</h2>
<p>The project's website is located at https://github.com/emn178/js-md5<br>
Author: Chen, Yi-Cyuan (emn178@gmail.com)</p></article>
</section>
@ -90,13 +129,13 @@ md5.base64(''); // 1B2M2Y8AsgTpgAmY7PhCfg==</code></pre><h2>License</h2><p>The p
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Md5_.html">Md5</a></li></ul><h3>Namespaces</h3><ul><li><a href="md5.html">md5</a></li></ul><h3>Global</h3><ul><li><a href="global.html#md5%2508">md5</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="md5_.html">md5</a></li><li><a href="md5.hmac.html">hmac</a></li></ul><h3>Classes</h3><ul><li><a href="HmacMd5.html">HmacMd5</a></li><li><a href="Md5.html">Md5</a></li></ul><h3>Global</h3><ul><li><a href="global.html#md5%2508">md5</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Oct 29 2017 20:15:53 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Sep 27 2023 21:32:04 GMT+0800 (台北標準時間)
</footer>
<script> prettyPrint(); </script>

File diff suppressed because it is too large Load Diff

@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Namespace: md5</title>
<title>JSDoc: Class: Md5</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
@ -17,7 +17,7 @@
<div id="main">
<h1 class="page-title">Namespace: md5</h1>
<h1 class="page-title">Class: Md5</h1>
@ -28,7 +28,7 @@
<header>
<h2>md5</h2>
<h2><span class="attribs"><span class="type-signature"></span></span>Md5<span class="signature">()</span><span class="type-signature"></span></h2>
</header>
@ -37,20 +37,20 @@
<div class="container-overview">
<div class="description"><a href="https://github.com/emn178/js-md5">js-md5</a></div>
<h4 class="name" id="Md5"><span class="type-signature"></span>new Md5<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
<dt class="tag-version">Version:</dt>
<dd class="tag-version"><ul class="dummy"><li>0.7.0</li></ul></dd>
<div class="description">
This is internal class.
</div>
@ -64,32 +64,19 @@
<dl class="details">
<dt class="tag-author">Author:</dt>
<dd class="tag-author">
<ul>
<li>Chen, Yi-Cyuan [emn178@gmail.com]</li>
</ul>
</dd>
<dt class="tag-copyright">Copyright:</dt>
<dd class="tag-copyright"><ul class="dummy"><li>Chen, Yi-Cyuan 2014-2017</li></ul></dd>
<dt class="tag-license">License:</dt>
<dd class="tag-license"><ul class="dummy"><li>MIT</li></ul></dd>
<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#line1">line 1</a>
</li></ul></dd>
@ -97,29 +84,37 @@
</dl>
</div>
<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#line317">line 317</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5_.html#.create">md5.create</a></li>
</ul>
</dd>
</dl>
<h3 class="subsection-title">Methods</h3>
@ -127,81 +122,57 @@
<h4 class="name" id=".array"><span class="type-signature">(static) </span>array<span class="signature">(message)</span><span class="type-signature"> &rarr; {Array}</span></h4>
<div class="description">
Output hash as bytes array
</div>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<h3 class="subsection-title">Methods</h3>
<tbody>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<h4 class="name" id="array"><span class="type-signature"></span>array<span class="signature">()</span><span class="type-signature"> &rarr; {Array}</span></h4>
<span class="param-type">String</span>
|
<span class="param-type">Array</span>
|
<span class="param-type">Uint8Array</span>
|
<span class="param-type">ArrayBuffer</span>
</td>
<div class="description">
Output hash as bytes array
</div>
<td class="description last">message to hash</td>
</tr>
</tbody>
</table>
@ -237,13 +208,20 @@
<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#line74">line 74</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line704">line 704</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5_.html#.array">md5.array</a></li>
</ul>
</dd>
</dl>
@ -260,6 +238,8 @@
<h5>Returns:</h5>
@ -288,7 +268,7 @@
<h5>Example</h5>
<pre class="prettyprint"><code>md5.array('The quick brown fox jumps over the lazy dog');</code></pre>
<pre class="prettyprint"><code>hash.array();</code></pre>
@ -298,7 +278,7 @@
<h4 class="name" id=".arrayBuffer"><span class="type-signature">(static) </span>arrayBuffer<span class="signature">(message)</span><span class="type-signature"> &rarr; {ArrayBuffer}</span></h4>
<h4 class="name" id="arrayBuffer"><span class="type-signature"></span>arrayBuffer<span class="signature">()</span><span class="type-signature"> &rarr; {ArrayBuffer}</span></h4>
@ -317,64 +297,6 @@
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type">String</span>
|
<span class="param-type">Array</span>
|
<span class="param-type">Uint8Array</span>
|
<span class="param-type">ArrayBuffer</span>
</td>
<td class="description last">message to hash</td>
</tr>
</tbody>
</table>
@ -408,13 +330,20 @@
<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#line83">line 83</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line716">line 716</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5_.html#.arrayBuffer">md5.arrayBuffer</a></li>
</ul>
</dd>
</dl>
@ -431,6 +360,8 @@
<h5>Returns:</h5>
@ -459,7 +390,7 @@
<h5>Example</h5>
<pre class="prettyprint"><code>md5.arrayBuffer('The quick brown fox jumps over the lazy dog');</code></pre>
<pre class="prettyprint"><code>hash.arrayBuffer();</code></pre>
@ -469,7 +400,7 @@
<h4 class="name" id=".base64"><span class="type-signature">(static) </span>base64<span class="signature">(message)</span><span class="type-signature"> &rarr; {String}</span></h4>
<h4 class="name" id="base64"><span class="type-signature"></span>base64<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
@ -488,64 +419,6 @@
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type">String</span>
|
<span class="param-type">Array</span>
|
<span class="param-type">Uint8Array</span>
|
<span class="param-type">ArrayBuffer</span>
</td>
<td class="description last">message to hash</td>
</tr>
</tbody>
</table>
@ -579,13 +452,20 @@
<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#line102">line 102</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line751">line 751</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5_.html#.base64">md5.base64</a></li>
</ul>
</dd>
</dl>
@ -602,6 +482,8 @@
<h5>Returns:</h5>
@ -630,7 +512,7 @@
<h5>Example</h5>
<pre class="prettyprint"><code>md5.base64('The quick brown fox jumps over the lazy dog');</code></pre>
<pre class="prettyprint"><code>hash.base64();</code></pre>
@ -640,7 +522,7 @@
<h4 class="name" id=".buffer"><span class="type-signature">(static) </span>buffer<span class="signature">(message)</span><span class="type-signature"> &rarr; {ArrayBuffer}</span></h4>
<h4 class="name" id="buffer"><span class="type-signature"></span>buffer<span class="signature">()</span><span class="type-signature"> &rarr; {ArrayBuffer}</span></h4>
@ -659,64 +541,6 @@
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type">String</span>
|
<span class="param-type">Array</span>
|
<span class="param-type">Uint8Array</span>
|
<span class="param-type">ArrayBuffer</span>
</td>
<td class="description last">message to hash</td>
</tr>
</tbody>
</table>
@ -752,13 +576,20 @@
<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#line92">line 92</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line738">line 738</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5_.html#.buffer">md5.buffer</a></li>
</ul>
</dd>
</dl>
@ -775,6 +606,8 @@
<h5>Returns:</h5>
@ -803,7 +636,7 @@
<h5>Example</h5>
<pre class="prettyprint"><code>md5.buffer('The quick brown fox jumps over the lazy dog');</code></pre>
<pre class="prettyprint"><code>hash.buffer();</code></pre>
@ -813,7 +646,7 @@
<h4 class="name" id=".create"><span class="type-signature">(static) </span>create<span class="signature">()</span><span class="type-signature"> &rarr; {<a href="Md5_.html">Md5</a>}</span></h4>
<h4 class="name" id="digest"><span class="type-signature"></span>digest<span class="signature">()</span><span class="type-signature"> &rarr; {Array}</span></h4>
@ -821,7 +654,7 @@
<div class="description">
Create Md5 object
Output hash as bytes array
</div>
@ -865,13 +698,20 @@
<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#line117">line 117</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line682">line 682</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5_.html#.digest">md5.digest</a></li>
</ul>
</dd>
</dl>
@ -888,11 +728,13 @@
<h5>Returns:</h5>
<div class="param-desc">
Md5 object.
Bytes array
</div>
@ -903,7 +745,7 @@
</dt>
<dd>
<span class="param-type"><a href="Md5_.html">Md5</a></span>
<span class="param-type">Array</span>
</dd>
@ -916,7 +758,7 @@
<h5>Example</h5>
<pre class="prettyprint"><code>var hash = md5.create();</code></pre>
<pre class="prettyprint"><code>hash.digest();</code></pre>
@ -926,7 +768,7 @@
<h4 class="name" id=".digest"><span class="type-signature">(static) </span>digest<span class="signature">(message)</span><span class="type-signature"> &rarr; {Array}</span></h4>
<h4 class="name" id="hex"><span class="type-signature"></span>hex<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
@ -934,7 +776,7 @@
<div class="description">
Output hash as bytes array
Output hash as hex string
</div>
@ -945,64 +787,6 @@
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type">String</span>
|
<span class="param-type">Array</span>
|
<span class="param-type">Uint8Array</span>
|
<span class="param-type">ArrayBuffer</span>
</td>
<td class="description last">message to hash</td>
</tr>
</tbody>
</table>
@ -1036,13 +820,20 @@
<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#line65">line 65</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line637">line 637</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5_.html#.hex">md5.hex</a></li>
</ul>
</dd>
</dl>
@ -1059,11 +850,13 @@
<h5>Returns:</h5>
<div class="param-desc">
Bytes array
Hex string
</div>
@ -1074,7 +867,7 @@
</dt>
<dd>
<span class="param-type">Array</span>
<span class="param-type">String</span>
</dd>
@ -1087,7 +880,7 @@
<h5>Example</h5>
<pre class="prettyprint"><code>md5.digest('The quick brown fox jumps over the lazy dog');</code></pre>
<pre class="prettyprint"><code>hash.hex();</code></pre>
@ -1097,7 +890,7 @@
<h4 class="name" id=".hex"><span class="type-signature">(static) </span>hex<span class="signature">(message)</span><span class="type-signature"> &rarr; {String}</span></h4>
<h4 class="name" id="toString"><span class="type-signature"></span>toString<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
@ -1116,64 +909,6 @@
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type">String</span>
|
<span class="param-type">Array</span>
|
<span class="param-type">Uint8Array</span>
|
<span class="param-type">ArrayBuffer</span>
</td>
<td class="description last">message to hash</td>
</tr>
</tbody>
</table>
@ -1207,13 +942,20 @@
<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#line54">line 54</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line670">line 670</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5_.html#.hex">md5.hex</a></li>
</ul>
</dd>
</dl>
@ -1230,6 +972,8 @@
<h5>Returns:</h5>
@ -1258,9 +1002,7 @@
<h5>Example</h5>
<pre class="prettyprint"><code>md5.hex('The quick brown fox jumps over the lazy dog');
// equal to
md5('The quick brown fox jumps over the lazy dog');</code></pre>
<pre class="prettyprint"><code>hash.toString();</code></pre>
@ -1270,7 +1012,7 @@ md5('The quick brown fox jumps over the lazy dog');</code></pre>
<h4 class="name" id=".update"><span class="type-signature">(static) </span>update<span class="signature">(message)</span><span class="type-signature"> &rarr; {<a href="Md5_.html">Md5</a>}</span></h4>
<h4 class="name" id="update"><span class="type-signature"></span>update<span class="signature">(message)</span><span class="type-signature"> &rarr; {<a href="Md5.html">Md5</a>}</span></h4>
@ -1278,7 +1020,7 @@ md5('The quick brown fox jumps over the lazy dog');</code></pre>
<div class="description">
Create and update Md5 object
Update hash
</div>
@ -1380,13 +1122,20 @@ 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#line125">line 125</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line345">line 345</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="md5_.html#.update">md5.update</a></li>
</ul>
</dd>
</dl>
@ -1403,6 +1152,8 @@ md5('The quick brown fox jumps over the lazy dog');</code></pre>
<h5>Returns:</h5>
@ -1418,7 +1169,7 @@ md5('The quick brown fox jumps over the lazy dog');</code></pre>
</dt>
<dd>
<span class="param-type"><a href="Md5_.html">Md5</a></span>
<span class="param-type"><a href="Md5.html">Md5</a></span>
</dd>
@ -1429,14 +1180,6 @@ md5('The quick brown fox jumps over the lazy dog');</code></pre>
<h5>Example</h5>
<pre class="prettyprint"><code>var hash = md5.update('The quick brown fox jumps over the lazy dog');
// equal to
var hash = md5.create();
hash.update('The quick brown fox jumps over the lazy dog');</code></pre>
@ -1454,13 +1197,13 @@ hash.update('The quick brown fox jumps over the lazy dog');</code></pre>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Md5_.html">Md5</a></li></ul><h3>Namespaces</h3><ul><li><a href="md5.html">md5</a></li></ul><h3>Global</h3><ul><li><a href="global.html#md5%2508">md5</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="md5_.html">md5</a></li><li><a href="md5.hmac.html">hmac</a></li></ul><h3>Classes</h3><ul><li><a href="HmacMd5.html">HmacMd5</a></li><li><a href="Md5.html">Md5</a></li></ul><h3>Global</h3><ul><li><a href="global.html#md5%2508">md5</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Oct 29 2017 20:15:53 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Sep 27 2023 21:32:04 GMT+0800 (台北標準時間)
</footer>
<script> prettyPrint(); </script>

@ -30,15 +30,16 @@
* [js-md5]{@link https://github.com/emn178/js-md5}
*
* @namespace md5
* @version 0.7.0
* @version 0.8.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2014-2017
* @copyright Chen, Yi-Cyuan 2014-2023
* @license MIT
*/
(function () {
'use strict';
var ERROR = 'input is invalid type';
var INPUT_ERROR = 'input is invalid type';
var FINALIZE_ERROR = 'finalize already called';
var WINDOW = typeof window === 'object';
var root = WINDOW ? window : {};
if (root.JS_MD5_NO_WINDOW) {
@ -67,18 +68,38 @@
blocks = new Uint32Array(buffer);
}
if (root.JS_MD5_NO_NODE_JS || !Array.isArray) {
Array.isArray = function (obj) {
var isArray = Array.isArray;
if (root.JS_MD5_NO_NODE_JS || !isArray) {
isArray = function (obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
};
}
if (ARRAY_BUFFER &amp;&amp; (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
ArrayBuffer.isView = function (obj) {
var isView = ArrayBuffer.isView;
if (ARRAY_BUFFER &amp;&amp; (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
isView = function (obj) {
return typeof obj === 'object' &amp;&amp; obj.buffer &amp;&amp; obj.buffer.constructor === ArrayBuffer;
};
}
// [message: string, isString: bool]
var formatMessage = function (message) {
var type = typeof message;
if (type === 'string') {
return [message, true];
}
if (type !== 'object' || message === null) {
throw new Error(INPUT_ERROR);
}
if (ARRAY_BUFFER &amp;&amp; message.constructor === ArrayBuffer) {
return [new Uint8Array(message), false];
}
if (!isArray(message) &amp;&amp; !isView(message)) {
throw new Error(INPUT_ERROR);
}
return [message, false];
}
/**
* @method hex
* @memberof md5
@ -181,21 +202,29 @@
};
var nodeWrap = function (method) {
var crypto = eval("require('crypto')");
var Buffer = eval("require('buffer').Buffer");
var crypto = require('crypto')
var Buffer = require('buffer').Buffer;
var bufferFrom;
if (Buffer.from &amp;&amp; !root.JS_MD5_NO_BUFFER_FROM) {
bufferFrom = Buffer.from;
} else {
bufferFrom = function (message) {
return new Buffer(message);
};
}
var nodeMethod = function (message) {
if (typeof message === 'string') {
return crypto.createHash('md5').update(message, 'utf8').digest('hex');
} else {
if (message === null || message === undefined) {
throw ERROR;
throw new Error(INPUT_ERROR);
} else if (message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
}
}
if (Array.isArray(message) || ArrayBuffer.isView(message) ||
if (isArray(message) || isView(message) ||
message.constructor === Buffer) {
return crypto.createHash('md5').update(new Buffer(message)).digest('hex');
return crypto.createHash('md5').update(bufferFrom(message)).digest('hex');
} else {
return method(message);
}
@ -203,6 +232,116 @@
return nodeMethod;
};
/**
* @namespace md5.hmac
*/
/**
* @method hex
* @memberof md5.hmac
* @description Output hash as hex string
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {String} Hex string
* @example
* md5.hmac.hex('key', 'The quick brown fox jumps over the lazy dog');
* // equal to
* md5.hmac('key', 'The quick brown fox jumps over the lazy dog');
*/
/**
* @method digest
* @memberof md5.hmac
* @description Output hash as bytes array
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {Array} Bytes array
* @example
* md5.hmac.digest('key', 'The quick brown fox jumps over the lazy dog');
*/
/**
* @method array
* @memberof md5.hmac
* @description Output hash as bytes array
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {Array} Bytes array
* @example
* md5.hmac.array('key', 'The quick brown fox jumps over the lazy dog');
*/
/**
* @method arrayBuffer
* @memberof md5.hmac
* @description Output hash as ArrayBuffer
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {ArrayBuffer} ArrayBuffer
* @example
* md5.hmac.arrayBuffer('key', 'The quick brown fox jumps over the lazy dog');
*/
/**
* @method buffer
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
* @memberof md5.hmac
* @description Output hash as ArrayBuffer
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {ArrayBuffer} ArrayBuffer
* @example
* md5.hmac.buffer('key', 'The quick brown fox jumps over the lazy dog');
*/
/**
* @method base64
* @memberof md5.hmac
* @description Output hash as base64 string
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {String} base64 string
* @example
* md5.hmac.base64('key', 'The quick brown fox jumps over the lazy dog');
*/
var createHmacOutputMethod = function (outputType) {
return function (key, message) {
return new HmacMd5(key, true).update(message)[outputType]();
};
};
/**
* @method create
* @memberof md5.hmac
* @description Create HmacMd5 object
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @returns {HmacMd5} HmacMd5 object.
* @example
* var hash = md5.hmac.create('key');
*/
/**
* @method update
* @memberof md5.hmac
* @description Create and update HmacMd5 object
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {HmacMd5} HmacMd5 object.
* @example
* var hash = md5.hmac.update('key', 'The quick brown fox jumps over the lazy dog');
* // equal to
* var hash = md5.hmac.create('key');
* hash.update('The quick brown fox jumps over the lazy dog');
*/
var createHmacMethod = function () {
var method = createHmacOutputMethod('hex');
method.create = function (key) {
return new HmacMd5(key);
};
method.update = function (key, message) {
return method.create(key).update(message);
};
for (var i = 0; i &lt; OUTPUT_TYPES.length; ++i) {
var type = OUTPUT_TYPES[i];
method[type] = createHmacOutputMethod(type);
}
return method;
};
/**
* Md5 class
* @class Md5
@ -226,7 +365,7 @@
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
}
this.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = 0;
this.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = this.hBytes = 0;
this.finalized = this.hashed = false;
this.first = true;
}
@ -242,26 +381,12 @@
*/
Md5.prototype.update = function (message) {
if (this.finalized) {
return;
throw new Error(FINALIZE_ERROR);
}
var notString, type = typeof message;
if (type !== 'string') {
if (type === 'object') {
if (message === null) {
throw ERROR;
} else if (ARRAY_BUFFER &amp;&amp; message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
} else if (!Array.isArray(message)) {
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
throw ERROR;
}
}
} else {
throw ERROR;
}
notString = true;
}
var result = formatMessage(message);
message = result[0];
var isString = result[1];
var code, index = 0, i, length = message.length, blocks = this.blocks;
var buffer8 = this.buffer8;
@ -275,34 +400,24 @@
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
}
if (notString) {
if (ARRAY_BUFFER) {
for (i = this.start; index &lt; length &amp;&amp; i &lt; 64; ++index) {
buffer8[i++] = message[index];
}
} else {
for (i = this.start; index &lt; length &amp;&amp; i &lt; 64; ++index) {
blocks[i >> 2] |= message[index] &lt;&lt; SHIFT[i++ &amp; 3];
}
}
} else {
if (isString) {
if (ARRAY_BUFFER) {
for (i = this.start; index &lt; length &amp;&amp; i &lt; 64; ++index) {
code = message.charCodeAt(index);
if (code &lt; 0x80) {
buffer8[i++] = code;
} else if (code &lt; 0x800) {
buffer8[i++] = 0xc0 | (code >> 6);
buffer8[i++] = 0xc0 | (code >>> 6);
buffer8[i++] = 0x80 | (code &amp; 0x3f);
} else if (code &lt; 0xd800 || code >= 0xe000) {
buffer8[i++] = 0xe0 | (code >> 12);
buffer8[i++] = 0x80 | ((code >> 6) &amp; 0x3f);
buffer8[i++] = 0xe0 | (code >>> 12);
buffer8[i++] = 0x80 | ((code >>> 6) &amp; 0x3f);
buffer8[i++] = 0x80 | (code &amp; 0x3f);
} else {
code = 0x10000 + (((code &amp; 0x3ff) &lt;&lt; 10) | (message.charCodeAt(++index) &amp; 0x3ff));
buffer8[i++] = 0xf0 | (code >> 18);
buffer8[i++] = 0x80 | ((code >> 12) &amp; 0x3f);
buffer8[i++] = 0x80 | ((code >> 6) &amp; 0x3f);
buffer8[i++] = 0xf0 | (code >>> 18);
buffer8[i++] = 0x80 | ((code >>> 12) &amp; 0x3f);
buffer8[i++] = 0x80 | ((code >>> 6) &amp; 0x3f);
buffer8[i++] = 0x80 | (code &amp; 0x3f);
}
}
@ -310,23 +425,33 @@
for (i = this.start; index &lt; length &amp;&amp; i &lt; 64; ++index) {
code = message.charCodeAt(index);
if (code &lt; 0x80) {
blocks[i >> 2] |= code &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >>> 2] |= code &lt;&lt; SHIFT[i++ &amp; 3];
} else if (code &lt; 0x800) {
blocks[i >> 2] |= (0xc0 | (code >> 6)) &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >> 2] |= (0x80 | (code &amp; 0x3f)) &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >>> 2] |= (0xc0 | (code >>> 6)) &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >>> 2] |= (0x80 | (code &amp; 0x3f)) &lt;&lt; SHIFT[i++ &amp; 3];
} else if (code &lt; 0xd800 || code >= 0xe000) {
blocks[i >> 2] |= (0xe0 | (code >> 12)) &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >> 2] |= (0x80 | ((code >> 6) &amp; 0x3f)) &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >> 2] |= (0x80 | (code &amp; 0x3f)) &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >>> 2] |= (0xe0 | (code >>> 12)) &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >>> 2] |= (0x80 | ((code >>> 6) &amp; 0x3f)) &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >>> 2] |= (0x80 | (code &amp; 0x3f)) &lt;&lt; SHIFT[i++ &amp; 3];
} else {
code = 0x10000 + (((code &amp; 0x3ff) &lt;&lt; 10) | (message.charCodeAt(++index) &amp; 0x3ff));
blocks[i >> 2] |= (0xf0 | (code >> 18)) &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >> 2] |= (0x80 | ((code >> 12) &amp; 0x3f)) &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >> 2] |= (0x80 | ((code >> 6) &amp; 0x3f)) &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >> 2] |= (0x80 | (code &amp; 0x3f)) &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >>> 2] |= (0xf0 | (code >>> 18)) &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >>> 2] |= (0x80 | ((code >>> 12) &amp; 0x3f)) &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >>> 2] |= (0x80 | ((code >>> 6) &amp; 0x3f)) &lt;&lt; SHIFT[i++ &amp; 3];
blocks[i >>> 2] |= (0x80 | (code &amp; 0x3f)) &lt;&lt; SHIFT[i++ &amp; 3];
}
}
}
} else {
if (ARRAY_BUFFER) {
for (i = this.start; index &lt; length &amp;&amp; i &lt; 64; ++index) {
buffer8[i++] = message[index];
}
} else {
for (i = this.start; index &lt; length &amp;&amp; i &lt; 64; ++index) {
blocks[i >>> 2] |= message[index] &lt;&lt; SHIFT[i++ &amp; 3];
}
}
}
this.lastByteIndex = i;
this.bytes += i - this.start;
@ -338,6 +463,10 @@
this.start = i;
}
}
if (this.bytes > 4294967295) {
this.hBytes += this.bytes / 4294967296 &lt;&lt; 0;
this.bytes = this.bytes % 4294967296;
}
return this;
};
@ -347,7 +476,7 @@
}
this.finalized = true;
var blocks = this.blocks, i = this.lastByteIndex;
blocks[i >> 2] |= EXTRA[i &amp; 3];
blocks[i >>> 2] |= EXTRA[i &amp; 3];
if (i >= 56) {
if (!this.hashed) {
this.hash();
@ -359,7 +488,7 @@
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
}
blocks[14] = this.bytes &lt;&lt; 3;
blocks[15] = this.bytes >> 29;
blocks[15] = this.hBytes &lt;&lt; 3 | this.bytes >>> 29;
this.hash();
};
@ -548,22 +677,22 @@
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
return HEX_CHARS[(h0 >> 4) &amp; 0x0F] + HEX_CHARS[h0 &amp; 0x0F] +
HEX_CHARS[(h0 >> 12) &amp; 0x0F] + HEX_CHARS[(h0 >> 8) &amp; 0x0F] +
HEX_CHARS[(h0 >> 20) &amp; 0x0F] + HEX_CHARS[(h0 >> 16) &amp; 0x0F] +
HEX_CHARS[(h0 >> 28) &amp; 0x0F] + HEX_CHARS[(h0 >> 24) &amp; 0x0F] +
HEX_CHARS[(h1 >> 4) &amp; 0x0F] + HEX_CHARS[h1 &amp; 0x0F] +
HEX_CHARS[(h1 >> 12) &amp; 0x0F] + HEX_CHARS[(h1 >> 8) &amp; 0x0F] +
HEX_CHARS[(h1 >> 20) &amp; 0x0F] + HEX_CHARS[(h1 >> 16) &amp; 0x0F] +
HEX_CHARS[(h1 >> 28) &amp; 0x0F] + HEX_CHARS[(h1 >> 24) &amp; 0x0F] +
HEX_CHARS[(h2 >> 4) &amp; 0x0F] + HEX_CHARS[h2 &amp; 0x0F] +
HEX_CHARS[(h2 >> 12) &amp; 0x0F] + HEX_CHARS[(h2 >> 8) &amp; 0x0F] +
HEX_CHARS[(h2 >> 20) &amp; 0x0F] + HEX_CHARS[(h2 >> 16) &amp; 0x0F] +
HEX_CHARS[(h2 >> 28) &amp; 0x0F] + HEX_CHARS[(h2 >> 24) &amp; 0x0F] +
HEX_CHARS[(h3 >> 4) &amp; 0x0F] + HEX_CHARS[h3 &amp; 0x0F] +
HEX_CHARS[(h3 >> 12) &amp; 0x0F] + HEX_CHARS[(h3 >> 8) &amp; 0x0F] +
HEX_CHARS[(h3 >> 20) &amp; 0x0F] + HEX_CHARS[(h3 >> 16) &amp; 0x0F] +
HEX_CHARS[(h3 >> 28) &amp; 0x0F] + HEX_CHARS[(h3 >> 24) &amp; 0x0F];
return HEX_CHARS[(h0 >>> 4) &amp; 0x0F] + HEX_CHARS[h0 &amp; 0x0F] +
HEX_CHARS[(h0 >>> 12) &amp; 0x0F] + HEX_CHARS[(h0 >>> 8) &amp; 0x0F] +
HEX_CHARS[(h0 >>> 20) &amp; 0x0F] + HEX_CHARS[(h0 >>> 16) &amp; 0x0F] +
HEX_CHARS[(h0 >>> 28) &amp; 0x0F] + HEX_CHARS[(h0 >>> 24) &amp; 0x0F] +
HEX_CHARS[(h1 >>> 4) &amp; 0x0F] + HEX_CHARS[h1 &amp; 0x0F] +
HEX_CHARS[(h1 >>> 12) &amp; 0x0F] + HEX_CHARS[(h1 >>> 8) &amp; 0x0F] +
HEX_CHARS[(h1 >>> 20) &amp; 0x0F] + HEX_CHARS[(h1 >>> 16) &amp; 0x0F] +
HEX_CHARS[(h1 >>> 28) &amp; 0x0F] + HEX_CHARS[(h1 >>> 24) &amp; 0x0F] +
HEX_CHARS[(h2 >>> 4) &amp; 0x0F] + HEX_CHARS[h2 &amp; 0x0F] +
HEX_CHARS[(h2 >>> 12) &amp; 0x0F] + HEX_CHARS[(h2 >>> 8) &amp; 0x0F] +
HEX_CHARS[(h2 >>> 20) &amp; 0x0F] + HEX_CHARS[(h2 >>> 16) &amp; 0x0F] +
HEX_CHARS[(h2 >>> 28) &amp; 0x0F] + HEX_CHARS[(h2 >>> 24) &amp; 0x0F] +
HEX_CHARS[(h3 >>> 4) &amp; 0x0F] + HEX_CHARS[h3 &amp; 0x0F] +
HEX_CHARS[(h3 >>> 12) &amp; 0x0F] + HEX_CHARS[(h3 >>> 8) &amp; 0x0F] +
HEX_CHARS[(h3 >>> 20) &amp; 0x0F] + HEX_CHARS[(h3 >>> 16) &amp; 0x0F] +
HEX_CHARS[(h3 >>> 28) &amp; 0x0F] + HEX_CHARS[(h3 >>> 24) &amp; 0x0F];
};
/**
@ -593,10 +722,10 @@
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
return [
h0 &amp; 0xFF, (h0 >> 8) &amp; 0xFF, (h0 >> 16) &amp; 0xFF, (h0 >> 24) &amp; 0xFF,
h1 &amp; 0xFF, (h1 >> 8) &amp; 0xFF, (h1 >> 16) &amp; 0xFF, (h1 >> 24) &amp; 0xFF,
h2 &amp; 0xFF, (h2 >> 8) &amp; 0xFF, (h2 >> 16) &amp; 0xFF, (h2 >> 24) &amp; 0xFF,
h3 &amp; 0xFF, (h3 >> 8) &amp; 0xFF, (h3 >> 16) &amp; 0xFF, (h3 >> 24) &amp; 0xFF
h0 &amp; 0xFF, (h0 >>> 8) &amp; 0xFF, (h0 >>> 16) &amp; 0xFF, (h0 >>> 24) &amp; 0xFF,
h1 &amp; 0xFF, (h1 >>> 8) &amp; 0xFF, (h1 >>> 16) &amp; 0xFF, (h1 >>> 24) &amp; 0xFF,
h2 &amp; 0xFF, (h2 >>> 8) &amp; 0xFF, (h2 >>> 16) &amp; 0xFF, (h2 >>> 24) &amp; 0xFF,
h3 &amp; 0xFF, (h3 >>> 8) &amp; 0xFF, (h3 >>> 16) &amp; 0xFF, (h3 >>> 24) &amp; 0xFF
];
};
@ -675,7 +804,75 @@
return base64Str;
};
/**
* HmacMd5 class
* @class HmacMd5
* @extends Md5
* @description This is internal class.
* @see {@link md5.hmac.create}
*/
function HmacMd5(key, sharedMemory) {
var i, result = formatMessage(key);
key = result[0];
if (result[1]) {
var bytes = [], length = key.length, index = 0, code;
for (i = 0; i &lt; length; ++i) {
code = key.charCodeAt(i);
if (code &lt; 0x80) {
bytes[index++] = code;
} else if (code &lt; 0x800) {
bytes[index++] = (0xc0 | (code >>> 6));
bytes[index++] = (0x80 | (code &amp; 0x3f));
} else if (code &lt; 0xd800 || code >= 0xe000) {
bytes[index++] = (0xe0 | (code >>> 12));
bytes[index++] = (0x80 | ((code >>> 6) &amp; 0x3f));
bytes[index++] = (0x80 | (code &amp; 0x3f));
} else {
code = 0x10000 + (((code &amp; 0x3ff) &lt;&lt; 10) | (key.charCodeAt(++i) &amp; 0x3ff));
bytes[index++] = (0xf0 | (code >>> 18));
bytes[index++] = (0x80 | ((code >>> 12) &amp; 0x3f));
bytes[index++] = (0x80 | ((code >>> 6) &amp; 0x3f));
bytes[index++] = (0x80 | (code &amp; 0x3f));
}
}
key = bytes;
}
if (key.length > 64) {
key = (new Md5(true)).update(key).array();
}
var oKeyPad = [], iKeyPad = [];
for (i = 0; i &lt; 64; ++i) {
var b = key[i] || 0;
oKeyPad[i] = 0x5c ^ b;
iKeyPad[i] = 0x36 ^ b;
}
Md5.call(this, sharedMemory);
this.update(iKeyPad);
this.oKeyPad = oKeyPad;
this.inner = true;
this.sharedMemory = sharedMemory;
}
HmacMd5.prototype = new Md5();
HmacMd5.prototype.finalize = function () {
Md5.prototype.finalize.call(this);
if (this.inner) {
this.inner = false;
var innerHash = this.array();
Md5.call(this, this.sharedMemory);
this.update(this.oKeyPad);
this.update(innerHash);
Md5.prototype.finalize.call(this);
}
};
var exports = createMethod();
exports.md5 = exports;
exports.md5.hmac = createHmacMethod();
if (COMMON_JS) {
module.exports = exports;
@ -715,13 +912,13 @@
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Md5_.html">Md5</a></li></ul><h3>Namespaces</h3><ul><li><a href="md5.html">md5</a></li></ul><h3>Global</h3><ul><li><a href="global.html#md5%2508">md5</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="md5_.html">md5</a></li><li><a href="md5.hmac.html">hmac</a></li></ul><h3>Classes</h3><ul><li><a href="HmacMd5.html">HmacMd5</a></li><li><a href="Md5.html">Md5</a></li></ul><h3>Global</h3><ul><li><a href="global.html#md5%2508">md5</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Oct 29 2017 20:15:53 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Wed Sep 27 2023 21:32:04 GMT+0800 (台北標準時間)
</footer>
<script> prettyPrint(); </script>

@ -1,12 +1,12 @@
/*global document */
(function() {
var source = document.getElementsByClassName('prettyprint source linenums');
var i = 0;
var lineNumber = 0;
var lineId;
var lines;
var totalLines;
var anchorHash;
(() => {
const source = document.getElementsByClassName('prettyprint source linenums');
let i = 0;
let lineNumber = 0;
let lineId;
let lines;
let totalLines;
let anchorHash;
if (source && source[0]) {
anchorHash = document.location.hash.substring(1);
@ -15,7 +15,7 @@
for (; i < totalLines; i++) {
lineNumber++;
lineId = 'line' + lineNumber;
lineId = `line${lineNumber}`;
lines[i].id = lineId;
if (lineId === anchorHash) {
lines[i].className += ' selected';

@ -273,7 +273,7 @@ tr > th:last-child { border-right: 1px solid #ddd; }
margin: 0;
}
.prettyprint
.source
{
border: 1px solid #ddd;
width: 80%;
@ -284,7 +284,7 @@ tr > th:last-child { border-right: 1px solid #ddd; }
width: inherit;
}
.prettyprint code
.source code
{
font-size: 100%;
line-height: 18px;

168
index.d.ts vendored

@ -0,0 +1,168 @@
type Message = string | number[] | ArrayBuffer | Uint8Array;
interface Hasher {
/**
* Update hash
*
* @param message The message you want to hash.
*/
update(message: Message): Hasher;
/**
* Return hash in hex string.
*/
hex(): string;
/**
* Return hash in hex string.
*/
toString(): string;
/**
* Return hash in ArrayBuffer.
*/
arrayBuffer(): ArrayBuffer;
/**
* Return hash in integer array.
*/
digest(): number[];
/**
* Return hash in integer array.
*/
array(): number[];
/**
* Return hash in base64 string.
*/
base64(): string;
}
interface Hmac {
/**
* Computes a Hash-based message authentication code (HMAC) using a secret key
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
(secretKey: Message, message: Message): string;
/**
* Create a hash object using a secret key.
*
* @param secretKey The Secret Key
*/
create(secretKey: Message): Hasher;
/**
* Create a hash object and hash message using a secret key
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
update(secretKey: Message, message: Message): Hasher;
/**
* Return hash in hex string.
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
hex(secretKey: Message, message: Message): string;
/**
* Return hash in ArrayBuffer.
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
arrayBuffer(secretKey: Message, message: Message): ArrayBuffer;
/**
* Return hash in integer array.
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
digest(secretKey: Message, message: Message): number[];
/**
* Return hash in integer array.
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
array(secretKey: Message, message: Message): number[];
/**
* Return hash in base64 string.
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
base64(secretKey: Message, message: Message): string;
}
interface Hash {
/**
* Hash and return hex string.
*
* @param message The message you want to hash.
*/
(message: Message): string;
/**
* Create a hash object.
*/
create(): Hasher;
/**
* Create a hash object and hash message.
*
* @param message The message you want to hash.
*/
update(message: Message): Hasher;
/**
* Return hash in hex string.
*
* @param message The message you want to hash.
*/
hex(message: Message): string;
/**
* Return hash in ArrayBuffer.
*
* @param message The message you want to hash.
*/
arrayBuffer(message: Message): ArrayBuffer;
/**
* Return hash in integer array.
*
* @param message The message you want to hash.
*/
digest(message: Message): number[];
/**
* Return hash in integer array.
*
* @param message The message you want to hash.
*/
array(message: Message): number[];
/**
* Return hash in base64 string.
*
* @param message The message you want to hash.
*/
base64(message: Message): string;
/**
* HMAC interface
*/
hmac: Hmac;
}
export var md5: Hash;

2443
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,23 +1,23 @@
{
"name": "js-md5",
"version": "0.7.0",
"version": "0.8.3",
"description": "A simple MD5 hash function for JavaScript supports UTF-8 encoding.",
"main": "src/md5.js",
"devDependencies": {
"expect.js": "~0.3.1",
"jscoverage": "~0.5.9",
"jsdoc": "^3.4.0",
"mocha": "~2.3.4",
"jsdoc": "~4.0.2",
"mocha": "~10.2.0",
"nyc": "^15.1.0",
"requirejs": "^2.1.22",
"uglify-js": "~2.4.10",
"webworker-threads": "^0.7.11"
"tiny-worker": "^2.3.0",
"uglify-js": "^3.1.9"
},
"scripts": {
"test": "mocha tests/node-test.js -r jscoverage",
"report": "mocha tests/node-test.js -r jscoverage --covout=html",
"coveralls": "mocha tests/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls",
"test": "nyc mocha tests/node-test.js",
"report": "nyc --reporter=html --reporter=text mocha tests/node-test.js",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"doc": "rm -rf doc;jsdoc src README.md -d doc",
"compress": "uglifyjs src/md5.js --compress --mangle --comments --output build/md5.min.js",
"compress": "uglifyjs src/md5.js -c -m eval --comments --output build/md5.min.js",
"build": "npm run-script compress;npm run-script doc"
},
"repository": {
@ -36,5 +36,14 @@
"homepage": "https://github.com/emn178/js-md5",
"bugs": {
"url": "https://github.com/emn178/js-md5/issues"
},
"nyc": {
"exclude": [
"tests"
]
},
"browser": {
"crypto": false,
"buffer": false
}
}

@ -2,15 +2,16 @@
* [js-md5]{@link https://github.com/emn178/js-md5}
*
* @namespace md5
* @version 0.7.0
* @version 0.8.3
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2014-2017
* @copyright Chen, Yi-Cyuan 2014-2023
* @license MIT
*/
(function () {
'use strict';
var ERROR = 'input is invalid type';
var INPUT_ERROR = 'input is invalid type';
var FINALIZE_ERROR = 'finalize already called';
var WINDOW = typeof window === 'object';
var root = WINDOW ? window : {};
if (root.JS_MD5_NO_WINDOW) {
@ -39,18 +40,38 @@
blocks = new Uint32Array(buffer);
}
if (root.JS_MD5_NO_NODE_JS || !Array.isArray) {
Array.isArray = function (obj) {
var isArray = Array.isArray;
if (root.JS_MD5_NO_NODE_JS || !isArray) {
isArray = function (obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
};
}
if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
ArrayBuffer.isView = function (obj) {
var isView = ArrayBuffer.isView;
if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
isView = function (obj) {
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
};
}
// [message: string, isString: bool]
var formatMessage = function (message) {
var type = typeof message;
if (type === 'string') {
return [message, true];
}
if (type !== 'object' || message === null) {
throw new Error(INPUT_ERROR);
}
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
return [new Uint8Array(message), false];
}
if (!isArray(message) && !isView(message)) {
throw new Error(INPUT_ERROR);
}
return [message, false];
}
/**
* @method hex
* @memberof md5
@ -153,21 +174,29 @@
};
var nodeWrap = function (method) {
var crypto = eval("require('crypto')");
var Buffer = eval("require('buffer').Buffer");
var crypto = require('crypto')
var Buffer = require('buffer').Buffer;
var bufferFrom;
if (Buffer.from && !root.JS_MD5_NO_BUFFER_FROM) {
bufferFrom = Buffer.from;
} else {
bufferFrom = function (message) {
return new Buffer(message);
};
}
var nodeMethod = function (message) {
if (typeof message === 'string') {
return crypto.createHash('md5').update(message, 'utf8').digest('hex');
} else {
if (message === null || message === undefined) {
throw ERROR;
throw new Error(INPUT_ERROR);
} else if (message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
}
}
if (Array.isArray(message) || ArrayBuffer.isView(message) ||
if (isArray(message) || isView(message) ||
message.constructor === Buffer) {
return crypto.createHash('md5').update(new Buffer(message)).digest('hex');
return crypto.createHash('md5').update(bufferFrom(message)).digest('hex');
} else {
return method(message);
}
@ -175,6 +204,116 @@
return nodeMethod;
};
/**
* @namespace md5.hmac
*/
/**
* @method hex
* @memberof md5.hmac
* @description Output hash as hex string
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {String} Hex string
* @example
* md5.hmac.hex('key', 'The quick brown fox jumps over the lazy dog');
* // equal to
* md5.hmac('key', 'The quick brown fox jumps over the lazy dog');
*/
/**
* @method digest
* @memberof md5.hmac
* @description Output hash as bytes array
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {Array} Bytes array
* @example
* md5.hmac.digest('key', 'The quick brown fox jumps over the lazy dog');
*/
/**
* @method array
* @memberof md5.hmac
* @description Output hash as bytes array
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {Array} Bytes array
* @example
* md5.hmac.array('key', 'The quick brown fox jumps over the lazy dog');
*/
/**
* @method arrayBuffer
* @memberof md5.hmac
* @description Output hash as ArrayBuffer
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {ArrayBuffer} ArrayBuffer
* @example
* md5.hmac.arrayBuffer('key', 'The quick brown fox jumps over the lazy dog');
*/
/**
* @method buffer
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
* @memberof md5.hmac
* @description Output hash as ArrayBuffer
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {ArrayBuffer} ArrayBuffer
* @example
* md5.hmac.buffer('key', 'The quick brown fox jumps over the lazy dog');
*/
/**
* @method base64
* @memberof md5.hmac
* @description Output hash as base64 string
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {String} base64 string
* @example
* md5.hmac.base64('key', 'The quick brown fox jumps over the lazy dog');
*/
var createHmacOutputMethod = function (outputType) {
return function (key, message) {
return new HmacMd5(key, true).update(message)[outputType]();
};
};
/**
* @method create
* @memberof md5.hmac
* @description Create HmacMd5 object
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @returns {HmacMd5} HmacMd5 object.
* @example
* var hash = md5.hmac.create('key');
*/
/**
* @method update
* @memberof md5.hmac
* @description Create and update HmacMd5 object
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {HmacMd5} HmacMd5 object.
* @example
* var hash = md5.hmac.update('key', 'The quick brown fox jumps over the lazy dog');
* // equal to
* var hash = md5.hmac.create('key');
* hash.update('The quick brown fox jumps over the lazy dog');
*/
var createHmacMethod = function () {
var method = createHmacOutputMethod('hex');
method.create = function (key) {
return new HmacMd5(key);
};
method.update = function (key, message) {
return method.create(key).update(message);
};
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
var type = OUTPUT_TYPES[i];
method[type] = createHmacOutputMethod(type);
}
return method;
};
/**
* Md5 class
* @class Md5
@ -198,7 +337,7 @@
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
}
this.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = 0;
this.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = this.hBytes = 0;
this.finalized = this.hashed = false;
this.first = true;
}
@ -214,26 +353,12 @@
*/
Md5.prototype.update = function (message) {
if (this.finalized) {
return;
throw new Error(FINALIZE_ERROR);
}
var notString, type = typeof message;
if (type !== 'string') {
if (type === 'object') {
if (message === null) {
throw ERROR;
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
} else if (!Array.isArray(message)) {
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
throw ERROR;
}
}
} else {
throw ERROR;
}
notString = true;
}
var result = formatMessage(message);
message = result[0];
var isString = result[1];
var code, index = 0, i, length = message.length, blocks = this.blocks;
var buffer8 = this.buffer8;
@ -247,34 +372,24 @@
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
}
if (notString) {
if (ARRAY_BUFFER) {
for (i = this.start; index < length && i < 64; ++index) {
buffer8[i++] = message[index];
}
} else {
for (i = this.start; index < length && i < 64; ++index) {
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
}
}
} else {
if (isString) {
if (ARRAY_BUFFER) {
for (i = this.start; index < length && i < 64; ++index) {
code = message.charCodeAt(index);
if (code < 0x80) {
buffer8[i++] = code;
} else if (code < 0x800) {
buffer8[i++] = 0xc0 | (code >> 6);
buffer8[i++] = 0xc0 | (code >>> 6);
buffer8[i++] = 0x80 | (code & 0x3f);
} else if (code < 0xd800 || code >= 0xe000) {
buffer8[i++] = 0xe0 | (code >> 12);
buffer8[i++] = 0x80 | ((code >> 6) & 0x3f);
buffer8[i++] = 0xe0 | (code >>> 12);
buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
buffer8[i++] = 0x80 | (code & 0x3f);
} else {
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
buffer8[i++] = 0xf0 | (code >> 18);
buffer8[i++] = 0x80 | ((code >> 12) & 0x3f);
buffer8[i++] = 0x80 | ((code >> 6) & 0x3f);
buffer8[i++] = 0xf0 | (code >>> 18);
buffer8[i++] = 0x80 | ((code >>> 12) & 0x3f);
buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
buffer8[i++] = 0x80 | (code & 0x3f);
}
}
@ -282,23 +397,33 @@
for (i = this.start; index < length && i < 64; ++index) {
code = message.charCodeAt(index);
if (code < 0x80) {
blocks[i >> 2] |= code << SHIFT[i++ & 3];
blocks[i >>> 2] |= code << SHIFT[i++ & 3];
} else if (code < 0x800) {
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
} else if (code < 0xd800 || code >= 0xe000) {
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
} else {
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
}
}
}
} else {
if (ARRAY_BUFFER) {
for (i = this.start; index < length && i < 64; ++index) {
buffer8[i++] = message[index];
}
} else {
for (i = this.start; index < length && i < 64; ++index) {
blocks[i >>> 2] |= message[index] << SHIFT[i++ & 3];
}
}
}
this.lastByteIndex = i;
this.bytes += i - this.start;
@ -310,6 +435,10 @@
this.start = i;
}
}
if (this.bytes > 4294967295) {
this.hBytes += this.bytes / 4294967296 << 0;
this.bytes = this.bytes % 4294967296;
}
return this;
};
@ -319,7 +448,7 @@
}
this.finalized = true;
var blocks = this.blocks, i = this.lastByteIndex;
blocks[i >> 2] |= EXTRA[i & 3];
blocks[i >>> 2] |= EXTRA[i & 3];
if (i >= 56) {
if (!this.hashed) {
this.hash();
@ -331,7 +460,7 @@
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
}
blocks[14] = this.bytes << 3;
blocks[15] = this.bytes >> 29;
blocks[15] = this.hBytes << 3 | this.bytes >>> 29;
this.hash();
};
@ -520,22 +649,22 @@
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
return HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] +
HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] +
HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] +
HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] +
HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] +
HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] +
HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] +
HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] +
HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] +
HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F];
return HEX_CHARS[(h0 >>> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
HEX_CHARS[(h0 >>> 12) & 0x0F] + HEX_CHARS[(h0 >>> 8) & 0x0F] +
HEX_CHARS[(h0 >>> 20) & 0x0F] + HEX_CHARS[(h0 >>> 16) & 0x0F] +
HEX_CHARS[(h0 >>> 28) & 0x0F] + HEX_CHARS[(h0 >>> 24) & 0x0F] +
HEX_CHARS[(h1 >>> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
HEX_CHARS[(h1 >>> 12) & 0x0F] + HEX_CHARS[(h1 >>> 8) & 0x0F] +
HEX_CHARS[(h1 >>> 20) & 0x0F] + HEX_CHARS[(h1 >>> 16) & 0x0F] +
HEX_CHARS[(h1 >>> 28) & 0x0F] + HEX_CHARS[(h1 >>> 24) & 0x0F] +
HEX_CHARS[(h2 >>> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
HEX_CHARS[(h2 >>> 12) & 0x0F] + HEX_CHARS[(h2 >>> 8) & 0x0F] +
HEX_CHARS[(h2 >>> 20) & 0x0F] + HEX_CHARS[(h2 >>> 16) & 0x0F] +
HEX_CHARS[(h2 >>> 28) & 0x0F] + HEX_CHARS[(h2 >>> 24) & 0x0F] +
HEX_CHARS[(h3 >>> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
HEX_CHARS[(h3 >>> 12) & 0x0F] + HEX_CHARS[(h3 >>> 8) & 0x0F] +
HEX_CHARS[(h3 >>> 20) & 0x0F] + HEX_CHARS[(h3 >>> 16) & 0x0F] +
HEX_CHARS[(h3 >>> 28) & 0x0F] + HEX_CHARS[(h3 >>> 24) & 0x0F];
};
/**
@ -565,10 +694,10 @@
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
return [
h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 24) & 0xFF,
h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 24) & 0xFF,
h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 24) & 0xFF,
h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 24) & 0xFF
h0 & 0xFF, (h0 >>> 8) & 0xFF, (h0 >>> 16) & 0xFF, (h0 >>> 24) & 0xFF,
h1 & 0xFF, (h1 >>> 8) & 0xFF, (h1 >>> 16) & 0xFF, (h1 >>> 24) & 0xFF,
h2 & 0xFF, (h2 >>> 8) & 0xFF, (h2 >>> 16) & 0xFF, (h2 >>> 24) & 0xFF,
h3 & 0xFF, (h3 >>> 8) & 0xFF, (h3 >>> 16) & 0xFF, (h3 >>> 24) & 0xFF
];
};
@ -647,7 +776,75 @@
return base64Str;
};
/**
* HmacMd5 class
* @class HmacMd5
* @extends Md5
* @description This is internal class.
* @see {@link md5.hmac.create}
*/
function HmacMd5(key, sharedMemory) {
var i, result = formatMessage(key);
key = result[0];
if (result[1]) {
var bytes = [], length = key.length, index = 0, code;
for (i = 0; i < length; ++i) {
code = key.charCodeAt(i);
if (code < 0x80) {
bytes[index++] = code;
} else if (code < 0x800) {
bytes[index++] = (0xc0 | (code >>> 6));
bytes[index++] = (0x80 | (code & 0x3f));
} else if (code < 0xd800 || code >= 0xe000) {
bytes[index++] = (0xe0 | (code >>> 12));
bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
bytes[index++] = (0x80 | (code & 0x3f));
} else {
code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff));
bytes[index++] = (0xf0 | (code >>> 18));
bytes[index++] = (0x80 | ((code >>> 12) & 0x3f));
bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
bytes[index++] = (0x80 | (code & 0x3f));
}
}
key = bytes;
}
if (key.length > 64) {
key = (new Md5(true)).update(key).array();
}
var oKeyPad = [], iKeyPad = [];
for (i = 0; i < 64; ++i) {
var b = key[i] || 0;
oKeyPad[i] = 0x5c ^ b;
iKeyPad[i] = 0x36 ^ b;
}
Md5.call(this, sharedMemory);
this.update(iKeyPad);
this.oKeyPad = oKeyPad;
this.inner = true;
this.sharedMemory = sharedMemory;
}
HmacMd5.prototype = new Md5();
HmacMd5.prototype.finalize = function () {
Md5.prototype.finalize.call(this);
if (this.inner) {
this.inner = false;
var innerHash = this.array();
Md5.call(this, this.sharedMemory);
this.update(this.oKeyPad);
this.update(innerHash);
Md5.prototype.finalize.call(this);
}
};
var exports = createMethod();
exports.md5 = exports;
exports.md5.hmac = createHmacMethod();
if (COMMON_JS) {
module.exports = exports;

@ -0,0 +1,202 @@
(function (md5) {
Array.prototype.toHexString = ArrayBuffer.prototype.toHexString = function () {
var array = new Uint8Array(this);
var hex = '';
for (var i = 0; i < array.length; ++i) {
var c = array[i].toString('16');
hex += c.length === 1 ? '0' + c : c;
}
return hex;
};
var testCases = {
md5_hmac: {
'Test Vectors': {
'9294727a3638bb1c13f48ef8158bfc9d': [
[0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b],
'Hi There'
],
'750c783e6ab0b503eaa86e310a5db738': [
'Jefe',
'what do ya want for nothing?'
],
'56be34521d144c88dbb8c733f0e8b3f6': [
[0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa],
[0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd]
],
'697eaf0aca3a3aea3a75164746ffaa79': [
[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19],
[0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd]
],
'56461ef2342edc00f9bab995690efd4c': [
[0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c],
'Test With Truncation'
],
'6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd': [
[0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa],
'Test Using Larger Than Block-Size Key - Hash Key First'
],
'6f630fad67cda0ee1fb1f562db3aa53e': [
[0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa],
'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data'
]
},
'UTF8': {
'05fe3b294344f4e93c811e10f9825a38': ['中文', '中文'],
'c1bc6df91f38e6332b8562324005103d': ['aécio', 'aécio'],
'14eef78533c35078177d11fb4593a19e': ['𠜎', '𠜎']
}
}
};
if (!(typeof JS_MD5_NO_ARRAY_BUFFER === 'boolean' && JS_MD5_NO_ARRAY_BUFFER)) {
testCases.md5_hmac.Uint8Array = {
'72c33c78cac0b7a581ac263a344ed01d': [
new Uint8Array(0),
'Hi There'
]
};
testCases.md5_hmac.ArrayBuffer = {
'72c33c78cac0b7a581ac263a344ed01d': [
new ArrayBuffer(0),
'Hi There'
]
};
}
var errorTestCases = [null, undefined, { length: 0 }, 0, 1, false, true, NaN, Infinity, function () {}];
function runTestCases(name, algorithm) {
var methods = [
{
name: name,
call: algorithm,
},
{
name: name + '.hex',
call: algorithm.hex
},
{
name: name + '.array',
call: function (key, message) {
return algorithm.array(key, message).toHexString();
}
},
{
name: name + '.digest',
call: function (key, message) {
return algorithm.digest(key, message).toHexString();
}
},
{
name: name + '.arrayBuffer',
call: function (key, message) {
return algorithm.arrayBuffer(key, message).toHexString();
}
}
];
var classMethods = [
{
name: 'create',
call: function (key, message) {
return algorithm.create(key).update(message).toString();
}
},
{
name: 'update',
call: function (key, message) {
return algorithm.update(key, message).toString();
}
},
{
name: 'hex',
call: function (key, message) {
return algorithm.update(key, message).hex();
}
},
{
name: 'array',
call: function (key, message) {
return algorithm.update(key, message).array().toHexString();
}
},
{
name: 'digest',
call: function (key, message) {
return algorithm.update(key, message).digest().toHexString();
}
},
{
name: 'arrayBuffer',
call: function (key, message) {
return algorithm.update(key, message).arrayBuffer().toHexString();
}
},
{
name: 'finalize',
call: function (key, message) {
var hash = algorithm.update(key, message);
hash.hex();
return hash.hex();
}
}
];
var subTestCases = testCases[name];
describe(name, function () {
methods.forEach(function (method) {
describe('#' + method.name, function () {
for (var testCaseName in subTestCases) {
(function (testCaseName) {
var testCase = subTestCases[testCaseName];
context('when ' + testCaseName, function () {
for (var hash in testCase) {
(function (message, hash) {
it('should be equal', function () {
expect(method.call(message[0], message[1])).to.be(hash);
});
})(testCase[hash], hash);
}
});
})(testCaseName);
}
});
});
classMethods.forEach(function (method) {
describe('#' + method.name, function () {
for (var testCaseName in subTestCases) {
(function (testCaseName) {
var testCase = subTestCases[testCaseName];
context('when ' + testCaseName, function () {
for (var hash in testCase) {
(function (message, hash) {
it('should be equal', function () {
expect(method.call(message[0], message[1])).to.be(hash);
});
})(testCase[hash], hash);
}
});
})(testCaseName);
}
});
});
describe('#' + name, function () {
errorTestCases.forEach(function (testCase) {
context('when ' + testCase, function () {
it('should throw error', function () {
expect(function () {
algorithm(testCase, '');
}).to.throwError(/input is invalid type/);
});
});
});
});
});
}
runTestCases('md5_hmac', md5.hmac);
})(md5);

@ -14,6 +14,7 @@
mocha.setup('bdd');
</script>
<script src="test.js"></script>
<script src="hmac-test.js"></script>
<script>
mocha.checkLeaks();
mocha.run();

@ -1,9 +1,10 @@
expect = require('expect.js');
Worker = require('webworker-threads').Worker;
Worker = require("tiny-worker");
function unset() {
delete require.cache[require.resolve('../src/md5.js')];
delete require.cache[require.resolve('./test.js')];
delete require.cache[require.resolve('./hmac-test.js')];
md5 = null;
BUFFER = undefined;
JS_MD5_NO_WINDOW = undefined;
@ -17,6 +18,7 @@ function unset() {
function runCommonJsTest() {
md5 = require('../src/md5.js');
require('./test.js');
require('./hmac-test.js');
unset();
}
@ -24,6 +26,7 @@ function runWindowTest() {
window = global;
require('../src/md5.js');
require('./test.js');
require('./hmac-test.js');
unset();
}
@ -31,6 +34,10 @@ function runWindowTest() {
BUFFER = true;
runCommonJsTest();
// Node.js env, no Buffer.from
JS_MD5_NO_BUFFER_FROM = true
runCommonJsTest();
// Webpack browser env
JS_MD5_NO_NODE_JS = true;
runCommonJsTest();
@ -59,6 +66,7 @@ window = global;
define = function (func) {
md5 = func();
require('./test.js');
require('./hmac-test.js');
};
define.amd = true;

@ -14,7 +14,7 @@
mocha.setup('bdd');
require(['../src/md5.js'], function (md5) {
window.md5 = md5;
require(['test.js'], function () {
require(['test.js', 'hmac-test.js'], function () {
mocha.checkLeaks();
mocha.run();
});

@ -96,8 +96,8 @@
if (typeof BUFFER === 'boolean' && BUFFER) {
testCases['Buffer'] = {
'd41d8cd98f00b204e9800998ecf8427e': new Buffer(0),
'9e107d9d372bb6826bd81d3542a419d6': new Buffer(new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]))
'd41d8cd98f00b204e9800998ecf8427e': Buffer.from([]),
'9e107d9d372bb6826bd81d3542a419d6': Buffer.from(new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]))
}
}
@ -186,7 +186,6 @@
call: function (message) {
var hash = md5.update(message);
hash.hex();
hash.update(message);
return hash.hex();
}
}
@ -241,8 +240,24 @@
});
});
});
});
context('when update after finalize', function () {
it('should throw error', function () {
expect(function () {
var hash = md5.update('any');
hash.hex();
hash.update('any');
}).to.throwError(/finalize already called/);
});
});
context('when large size', function () {
var hash = md5.create();
hash.bytes = 4294967295;
hash.update('any');
expect(hash.hBytes).to.be(1);
});
});
describe('#bas64', function () {
for (var testCaseName in base64TestCases) {

@ -11,6 +11,9 @@
var worker = new Worker(WORKER);
worker.onmessage = function(event) {
expect(event.data).to.be(hash);
if (worker.terminate) {
worker.terminate();
}
done();
};
worker.postMessage(SOURCE);

@ -17,7 +17,6 @@
</script>
<script src="worker-test.js"></script>
<script>
mocha.checkLeaks();
mocha.run();
</script>
<script>

Loading…
Cancel
Save