mirror of
https://github.com/emn178/js-md5.git
synced 2026-08-12 20:31:43 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ecaeee185 | ||
|
|
daf1188dc6 | ||
|
|
a9de3df8c6 | ||
|
|
08049ec6fa | ||
|
|
bdf1150097 | ||
|
|
c2e8d8683d | ||
|
|
c154bc5a38 | ||
|
|
0263ab835f | ||
|
|
5f0bd5a888 | ||
|
|
cb8eb73ef1 | ||
|
|
24d8eb504d | ||
|
|
a54f102b8a | ||
|
|
e7f1ca7da8 | ||
|
|
b808ed4605 | ||
|
|
2bdc4894fc | ||
|
|
c00df3af37 | ||
|
|
8b9a23ce32 | ||
|
|
da009f933f | ||
|
|
5fcee84417 |
@@ -1,2 +0,0 @@
|
|||||||
/tests/
|
|
||||||
node_modules/
|
|
||||||
+4
-2
@@ -1,2 +1,4 @@
|
|||||||
covreporter
|
/node_modules/
|
||||||
node_modules
|
/covreporter/
|
||||||
|
/.nyc_output/
|
||||||
|
/coverage/
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/node_modules/
|
||||||
|
/coverage/
|
||||||
|
/.nyc_output/
|
||||||
|
/tests/
|
||||||
|
/doc/
|
||||||
|
.covignore
|
||||||
|
.travis.yml
|
||||||
|
.npmignore
|
||||||
|
bower.json
|
||||||
+3
-7
@@ -1,14 +1,10 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "4.1"
|
- "6.11.4"
|
||||||
- "4.0"
|
- "8.6.0"
|
||||||
- "0.12"
|
|
||||||
- "0.11"
|
|
||||||
- "0.10"
|
|
||||||
before_install:
|
before_install:
|
||||||
- npm install coveralls
|
- npm install coveralls
|
||||||
- npm install mocha-lcov-reporter
|
after_success: npm run coveralls
|
||||||
script: npm run-script coveralls
|
|
||||||
branches:
|
branches:
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
|
|||||||
+108
-30
@@ -1,49 +1,127 @@
|
|||||||
# v0.4.0 / 2015-12-28
|
# Change Log
|
||||||
|
|
||||||
* Added support for update hash.
|
## v0.8.2 / 2023-10-09
|
||||||
* Added support for bytes array output.
|
### Remove
|
||||||
* Added support for ArrayBuffer output.
|
- package.json module property.
|
||||||
* Added support for AMD.
|
|
||||||
|
|
||||||
# v0.3.0 / 2015-03-07
|
## v0.8.1 / 2023-10-09
|
||||||
|
### Added
|
||||||
|
- TypeScript base64 interfaces.
|
||||||
|
- Disable webpack polyfill.
|
||||||
|
|
||||||
* Support byte Array, Uint8Array and ArrayBuffer input.
|
## v0.8.0 / 2023-09-27
|
||||||
|
### Added
|
||||||
|
- TypeScript interfaces.
|
||||||
|
- HMAC feature.
|
||||||
|
|
||||||
# v0.2.2 / 2015-02-01
|
### 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.
|
||||||
|
|
||||||
* Fixed bug when special length.
|
### Changed
|
||||||
* Improve performance for node.js.
|
- remove `eval` and use `require` directly.
|
||||||
|
- throw error by Error oject.
|
||||||
|
- throw error if update after finalize
|
||||||
|
- use unsigned right shift.
|
||||||
|
|
||||||
# v0.2.1 / 2015-01-13
|
## v0.7.3 / 2017-12-18
|
||||||
|
### Fixed
|
||||||
|
- incorrect result when first bit is 1 of bytes. #18
|
||||||
|
|
||||||
* Improve performance.
|
## v0.7.2 / 2017-10-31
|
||||||
|
### Improved
|
||||||
|
- performance of hBytes increment.
|
||||||
|
|
||||||
# v0.2.0 / 2015-01-12
|
## v0.7.1 / 2017-10-29
|
||||||
|
### Fixed
|
||||||
|
- incorrect result when file size >= 4G.
|
||||||
|
|
||||||
* Remove ascii parameter.
|
## v0.7.0 / 2017-10-29
|
||||||
* Improve performance.
|
### Fixed
|
||||||
|
- incorrect result when file size >= 512M.
|
||||||
|
|
||||||
# v0.1.4 / 2015-01-11
|
## v0.6.1 / 2017-10-07
|
||||||
|
### Fixed
|
||||||
|
- ArrayBuffer.isView issue in IE10.
|
||||||
|
|
||||||
* Improve performance.
|
### Improved
|
||||||
* Add test case.
|
- performance of input check.
|
||||||
|
|
||||||
# v0.1.3 / 2015-01-05
|
## v0.6.0 / 2017-07-28
|
||||||
|
### Added
|
||||||
|
- support base64 string output.
|
||||||
|
|
||||||
* Improve performance.
|
## v0.5.0 / 2017-07-14
|
||||||
* Add bower package.
|
### Added
|
||||||
* Fixed JSHint warnings.
|
- support for web worker. #11
|
||||||
* Add travis.
|
|
||||||
* Add coveralls.
|
|
||||||
|
|
||||||
# v0.1.2 / 2014-07-27
|
### Changed
|
||||||
|
- throw error if input type is incorrect.
|
||||||
|
- prevent webpack to require dependencies.
|
||||||
|
|
||||||
Fixed accents bug
|
## v0.4.2 / 2017-01-18
|
||||||
|
### Fixed
|
||||||
|
- `root` is undefined in some special environment. #7
|
||||||
|
|
||||||
# v0.1.1 / 2014-01-05
|
## v0.4.1 / 2016-03-31
|
||||||
|
### Removed
|
||||||
|
- length detection in node.js.
|
||||||
|
### Deprecated
|
||||||
|
- `buffer` and replace by `arrayBuffer`.
|
||||||
|
|
||||||
Update license
|
## v0.4.0 / 2015-12-28
|
||||||
|
### Added
|
||||||
|
- support for update hash.
|
||||||
|
- support for bytes array output.
|
||||||
|
- support for ArrayBuffer output.
|
||||||
|
- support for AMD.
|
||||||
|
|
||||||
# v0.1.0 / 2014-01-04
|
## v0.3.0 / 2015-03-07
|
||||||
|
### Added
|
||||||
|
- support byte Array, Uint8Array and ArrayBuffer input.
|
||||||
|
|
||||||
Initial release
|
## v0.2.2 / 2015-02-01
|
||||||
|
### Fixed
|
||||||
|
- bug when special length.
|
||||||
|
### Improve
|
||||||
|
- performance for node.js.
|
||||||
|
|
||||||
|
## v0.2.1 / 2015-01-13
|
||||||
|
### Improve
|
||||||
|
- performance.
|
||||||
|
|
||||||
|
## v0.2.0 / 2015-01-12
|
||||||
|
### Removed
|
||||||
|
- ascii parameter.
|
||||||
|
### Improve
|
||||||
|
- performance.
|
||||||
|
|
||||||
|
## v0.1.4 / 2015-01-11
|
||||||
|
### Improve
|
||||||
|
- performance.
|
||||||
|
### Added
|
||||||
|
- test cases.
|
||||||
|
|
||||||
|
## v0.1.3 / 2015-01-05
|
||||||
|
### Added
|
||||||
|
- bower package.
|
||||||
|
- travis.
|
||||||
|
- coveralls.
|
||||||
|
### Improved
|
||||||
|
- performance.
|
||||||
|
### Fixed
|
||||||
|
- JSHint warnings.
|
||||||
|
|
||||||
|
## v0.1.2 / 2014-07-27
|
||||||
|
### Fixed
|
||||||
|
- accents bug
|
||||||
|
|
||||||
|
## v0.1.1 / 2014-01-05
|
||||||
|
### Changed
|
||||||
|
- license
|
||||||
|
|
||||||
|
## v0.1.0 / 2014-01-04
|
||||||
|
### Added
|
||||||
|
- initial release
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
Copyright 2014-2015 Yi-Cyuan Chen
|
Copyright 2014-2023 Chen, Yi-Cyuan
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
[](https://travis-ci.org/emn178/js-md5)
|
[](https://travis-ci.org/emn178/js-md5)
|
||||||
[](https://coveralls.io/r/emn178/js-md5?branch=master)
|
[](https://coveralls.io/r/emn178/js-md5?branch=master)
|
||||||
[](https://nodei.co/npm/js-md5/)
|
[](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
|
## Demo
|
||||||
[MD5 Online](http://emn178.github.io/online-tools/md5.html)
|
[MD5 Online](http://emn178.github.io/online-tools/md5.html)
|
||||||
@@ -12,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)
|
[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)
|
[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
|
## Installation
|
||||||
You can also install js-md5 by using Bower.
|
You can also install js-md5 by using Bower.
|
||||||
|
|
||||||
@@ -21,6 +26,9 @@ For node.js, you can use this command to install:
|
|||||||
|
|
||||||
npm install js-md5
|
npm install js-md5
|
||||||
|
|
||||||
|
## Notice
|
||||||
|
`buffer` method is deprecated. This maybe confuse with Buffer in node.js. Please use `arrayBuffer` instead.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
You could use like this:
|
You could use like this:
|
||||||
```JavaScript
|
```JavaScript
|
||||||
@@ -28,11 +36,28 @@ md5('Message to hash');
|
|||||||
var hash = md5.create();
|
var hash = md5.create();
|
||||||
hash.update('Message to hash');
|
hash.update('Message to hash');
|
||||||
hash.hex();
|
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:
|
If you use node.js, you should require the module first:
|
||||||
```JavaScript
|
```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:
|
It supports AMD:
|
||||||
```JavaScript
|
```JavaScript
|
||||||
require(['your/path/md5.js'], function(md5) {
|
require(['your/path/md5.js'], function(md5) {
|
||||||
@@ -59,16 +84,19 @@ md5(''); // d41d8cd98f00b204e9800998ecf8427e
|
|||||||
md5.hex(''); // d41d8cd98f00b204e9800998ecf8427e
|
md5.hex(''); // d41d8cd98f00b204e9800998ecf8427e
|
||||||
md5.array(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126]
|
md5.array(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126]
|
||||||
md5.digest(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126]
|
md5.digest(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126]
|
||||||
md5.buffer(''); // ArrayBuffer
|
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');
|
||||||
|
// ...
|
||||||
```
|
```
|
||||||
|
|
||||||
## Benchmark
|
|
||||||
[UTF8](http://jsperf.com/md5-shootout/81)
|
|
||||||
[ASCII](http://jsperf.com/md5-shootout/82)
|
|
||||||
|
|
||||||
## License
|
## 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
|
## Contact
|
||||||
The project's website is located at https://github.com/emn178/js-md5
|
The project's website is located at https://github.com/emn178/js-md5
|
||||||
Author: Yi-Cyuan Chen (emn178@gmail.com)
|
Author: Chen, Yi-Cyuan (emn178@gmail.com)
|
||||||
|
|||||||
+1
-2
@@ -1,9 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "js-md5",
|
"name": "js-md5",
|
||||||
"version": "0.4.0",
|
"version": "0.8.2",
|
||||||
"main": ["src/md5.js"],
|
"main": ["src/md5.js"],
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"samples",
|
|
||||||
"tests"
|
"tests"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+4
-4
File diff suppressed because one or more lines are too long
+1263
File diff suppressed because it is too large
Load Diff
+1204
-634
File diff suppressed because it is too large
Load Diff
+11
-3
@@ -94,6 +94,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3 class="subsection-title">Methods</h3>
|
<h3 class="subsection-title">Methods</h3>
|
||||||
|
|
||||||
|
|
||||||
@@ -101,12 +103,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h4 class="name" id="md5%08"><span class="type-signature"></span>md5<span class="signature">(message)</span><span class="type-signature"> → {String}</span></h4>
|
<h4 class="name" id="md5%08"><span class="type-signature"></span>md5<span class="signature">(message)</span><span class="type-signature"> → {String}</span></h4>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="description">
|
<div class="description">
|
||||||
Md5 hash function, export to global in browsers.
|
Md5 hash function, export to global in browsers.
|
||||||
</div>
|
</div>
|
||||||
@@ -210,7 +214,7 @@
|
|||||||
|
|
||||||
<dt class="tag-source">Source:</dt>
|
<dt class="tag-source">Source:</dt>
|
||||||
<dd class="tag-source"><ul class="dummy"><li>
|
<dd class="tag-source"><ul class="dummy"><li>
|
||||||
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line589">line 589</a>
|
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line852">line 852</a>
|
||||||
</li></ul></dd>
|
</li></ul></dd>
|
||||||
|
|
||||||
|
|
||||||
@@ -233,6 +237,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h5>Returns:</h5>
|
<h5>Returns:</h5>
|
||||||
|
|
||||||
|
|
||||||
@@ -257,6 +263,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h5>Example</h5>
|
<h5>Example</h5>
|
||||||
|
|
||||||
<pre class="prettyprint"><code>md5(''); // d41d8cd98f00b204e9800998ecf8427e
|
<pre class="prettyprint"><code>md5(''); // d41d8cd98f00b204e9800998ecf8427e
|
||||||
@@ -288,13 +296,13 @@ md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e</code></pre>
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav>
|
<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>
|
</nav>
|
||||||
|
|
||||||
<br class="clear">
|
<br class="clear">
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Dec 28 2015 15:48:48 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>
|
</footer>
|
||||||
|
|
||||||
<script> prettyPrint(); </script>
|
<script> prettyPrint(); </script>
|
||||||
|
|||||||
+58
-16
@@ -43,22 +43,53 @@
|
|||||||
|
|
||||||
|
|
||||||
<section>
|
<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>
|
<article><h1>js-md5</h1>
|
||||||
<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&downloads" alt="NPM"></a><br>A simple MD5 hash function for JavaScript supports UTF-8 encoding.</p>
|
<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>
|
||||||
<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>
|
<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>
|
||||||
<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>
|
<a href="https://nodei.co/npm/js-md5/"><img src="https://nodei.co/npm/js-md5.png?stars&downloads" alt="NPM"></a></p>
|
||||||
<h2>Installation</h2><p>You can also install js-md5 by using Bower.</p>
|
<p>A simple MD5 hash function for JavaScript supports UTF-8 encoding.</p>
|
||||||
<pre class="prettyprint source"><code>bower install md5</code></pre><p>For node.js, you can use this command to install:</p>
|
<h2>Demo</h2>
|
||||||
<pre class="prettyprint source"><code>npm install js-md5</code></pre><h2>Usage</h2><p>You could use like this:</p>
|
<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');
|
<pre class="prettyprint source lang-JavaScript"><code>md5('Message to hash');
|
||||||
var hash = md5.create();
|
var hash = md5.create();
|
||||||
hash.update('Message to hash');
|
hash.update('Message to hash');
|
||||||
hash.hex();</code></pre><p>If you use node.js, you should require the module first:</p>
|
hash.hex();
|
||||||
<pre class="prettyprint source lang-JavaScript"><code>md5 = require('js-md5');</code></pre><p>It supports AMD:</p>
|
|
||||||
|
// 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) {
|
<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'); // 9e107d9d372bb6826bd81d3542a419d6
|
||||||
md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0
|
md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0
|
||||||
|
|
||||||
@@ -74,9 +105,20 @@ md5(''); // d41d8cd98f00b204e9800998ecf8427e
|
|||||||
md5.hex(''); // d41d8cd98f00b204e9800998ecf8427e
|
md5.hex(''); // d41d8cd98f00b204e9800998ecf8427e
|
||||||
md5.array(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126]
|
md5.array(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126]
|
||||||
md5.digest(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126]
|
md5.digest(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126]
|
||||||
md5.buffer(''); // ArrayBuffer</code></pre><h2>Benchmark</h2><p><a href="http://jsperf.com/md5-shootout/81">UTF8</a><br><a href="http://jsperf.com/md5-shootout/82">ASCII</a></p>
|
md5.arrayBuffer(''); // ArrayBuffer
|
||||||
<h2>License</h2><p>The project is released under the <a href="http://www.opensource.org/licenses/MIT">MIT license</a>.</p>
|
md5.buffer(''); // ArrayBuffer, deprecated, This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
|
||||||
<h2>Contact</h2><p>The project's website is located at https://github.com/emn178/js-md5<br>Author: Yi-Cyuan Chen (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>
|
</section>
|
||||||
|
|
||||||
|
|
||||||
@@ -87,13 +129,13 @@ md5.buffer(''); // ArrayBuffer</code></pre><h2>Benchmark</h2><p><a href="http://
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav>
|
<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>
|
</nav>
|
||||||
|
|
||||||
<br class="clear">
|
<br class="clear">
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Dec 28 2015 15:48:48 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>
|
</footer>
|
||||||
|
|
||||||
<script> prettyPrint(); </script>
|
<script> prettyPrint(); </script>
|
||||||
|
|||||||
+1750
File diff suppressed because it is too large
Load Diff
+396
-518
File diff suppressed because it is too large
Load Diff
+377
-114
@@ -30,25 +30,36 @@
|
|||||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||||
*
|
*
|
||||||
* @namespace md5
|
* @namespace md5
|
||||||
* @version 0.4.0
|
* @version 0.8.0
|
||||||
* @author Yi-Cyuan Chen [emn178@gmail.com]
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||||
* @copyright Yi-Cyuan Chen 2014-2015
|
* @copyright Chen, Yi-Cyuan 2014-2023
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
(function (root) {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var NODE_JS = typeof process == 'object' && process.versions && process.versions.node;
|
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) {
|
||||||
|
WINDOW = false;
|
||||||
|
}
|
||||||
|
var WEB_WORKER = !WINDOW && typeof self === 'object';
|
||||||
|
var NODE_JS = !root.JS_MD5_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
|
||||||
if (NODE_JS) {
|
if (NODE_JS) {
|
||||||
root = global;
|
root = global;
|
||||||
|
} else if (WEB_WORKER) {
|
||||||
|
root = self;
|
||||||
}
|
}
|
||||||
var COMMON_JS = !root.JS_MD5_TEST && typeof module == 'object' && module.exports;
|
var COMMON_JS = !root.JS_MD5_NO_COMMON_JS && typeof module === 'object' && module.exports;
|
||||||
var AMD = typeof define == 'function' && define.amd;
|
var AMD = typeof define === 'function' && define.amd;
|
||||||
var ARRAY_BUFFER = !root.JS_MD5_TEST && typeof ArrayBuffer != 'undefined';
|
var ARRAY_BUFFER = !root.JS_MD5_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
|
||||||
var HEX_CHARS = '0123456789abcdef'.split('');
|
var HEX_CHARS = '0123456789abcdef'.split('');
|
||||||
var EXTRA = [128, 32768, 8388608, -2147483648];
|
var EXTRA = [128, 32768, 8388608, -2147483648];
|
||||||
var SHIFT = [0, 8, 16, 24];
|
var SHIFT = [0, 8, 16, 24];
|
||||||
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer'];
|
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer', 'base64'];
|
||||||
|
var BASE64_ENCODE_CHAR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
|
||||||
|
|
||||||
var blocks = [], buffer8;
|
var blocks = [], buffer8;
|
||||||
if (ARRAY_BUFFER) {
|
if (ARRAY_BUFFER) {
|
||||||
@@ -57,6 +68,38 @@
|
|||||||
blocks = new Uint32Array(buffer);
|
blocks = new Uint32Array(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isArray = Array.isArray;
|
||||||
|
if (root.JS_MD5_NO_NODE_JS || !isArray) {
|
||||||
|
isArray = function (obj) {
|
||||||
|
return Object.prototype.toString.call(obj) === '[object Array]';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
* @method hex
|
||||||
* @memberof md5
|
* @memberof md5
|
||||||
@@ -86,8 +129,18 @@
|
|||||||
* @example
|
* @example
|
||||||
* md5.array('The quick brown fox jumps over the lazy dog');
|
* md5.array('The quick brown fox jumps over the lazy dog');
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* @method arrayBuffer
|
||||||
|
* @memberof md5
|
||||||
|
* @description Output hash as ArrayBuffer
|
||||||
|
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||||
|
* @returns {ArrayBuffer} ArrayBuffer
|
||||||
|
* @example
|
||||||
|
* md5.arrayBuffer('The quick brown fox jumps over the lazy dog');
|
||||||
|
*/
|
||||||
/**
|
/**
|
||||||
* @method buffer
|
* @method buffer
|
||||||
|
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
|
||||||
* @memberof md5
|
* @memberof md5
|
||||||
* @description Output hash as ArrayBuffer
|
* @description Output hash as ArrayBuffer
|
||||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||||
@@ -95,10 +148,19 @@
|
|||||||
* @example
|
* @example
|
||||||
* md5.buffer('The quick brown fox jumps over the lazy dog');
|
* md5.buffer('The quick brown fox jumps over the lazy dog');
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* @method base64
|
||||||
|
* @memberof md5
|
||||||
|
* @description Output hash as base64 string
|
||||||
|
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||||
|
* @returns {String} base64 string
|
||||||
|
* @example
|
||||||
|
* md5.base64('The quick brown fox jumps over the lazy dog');
|
||||||
|
*/
|
||||||
var createOutputMethod = function (outputType) {
|
var createOutputMethod = function (outputType) {
|
||||||
return function(message) {
|
return function (message) {
|
||||||
return new Md5(true).update(message)[outputType]();
|
return new Md5(true).update(message)[outputType]();
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,7 +194,7 @@
|
|||||||
method.update = function (message) {
|
method.update = function (message) {
|
||||||
return method.create().update(message);
|
return method.create().update(message);
|
||||||
};
|
};
|
||||||
for (var i = 0;i < OUTPUT_TYPES.length;++i) {
|
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
||||||
var type = OUTPUT_TYPES[i];
|
var type = OUTPUT_TYPES[i];
|
||||||
method[type] = createOutputMethod(type);
|
method[type] = createOutputMethod(type);
|
||||||
}
|
}
|
||||||
@@ -140,58 +202,145 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
var nodeWrap = function (method) {
|
var nodeWrap = function (method) {
|
||||||
var crypto, Buffer;
|
var crypto = require('crypto')
|
||||||
try {
|
var Buffer = require('buffer').Buffer;
|
||||||
if (root.JS_MD5_TEST) {
|
var bufferFrom;
|
||||||
throw 'JS_MD5_TEST';
|
if (Buffer.from && !root.JS_MD5_NO_BUFFER_FROM) {
|
||||||
}
|
bufferFrom = Buffer.from;
|
||||||
crypto = require('crypto');
|
} else {
|
||||||
Buffer = require('buffer').Buffer;
|
bufferFrom = function (message) {
|
||||||
} catch (e) {
|
return new Buffer(message);
|
||||||
console.log(e);
|
};
|
||||||
return method;
|
|
||||||
}
|
}
|
||||||
var nodeMethod = function (message) {
|
var nodeMethod = function (message) {
|
||||||
if (typeof message == 'string') {
|
if (typeof message === 'string') {
|
||||||
if (message.length <= nodeMethod.utf8Threshold) {
|
|
||||||
return method(message);
|
|
||||||
} else if (message.length <= nodeMethod.asciiThreshold && !/[^\x00-\x7F]/.test(message)) {
|
|
||||||
return method(message);
|
|
||||||
}
|
|
||||||
return crypto.createHash('md5').update(message, 'utf8').digest('hex');
|
return crypto.createHash('md5').update(message, 'utf8').digest('hex');
|
||||||
} else if (message.constructor == ArrayBuffer) {
|
} else {
|
||||||
|
if (message === null || message === undefined) {
|
||||||
|
throw new Error(INPUT_ERROR);
|
||||||
|
} else if (message.constructor === ArrayBuffer) {
|
||||||
message = new Uint8Array(message);
|
message = new Uint8Array(message);
|
||||||
} else if (message.length === undefined || message.length <= nodeMethod.bytesThreshold) {
|
}
|
||||||
|
}
|
||||||
|
if (isArray(message) || isView(message) ||
|
||||||
|
message.constructor === Buffer) {
|
||||||
|
return crypto.createHash('md5').update(bufferFrom(message)).digest('hex');
|
||||||
|
} else {
|
||||||
return method(message);
|
return method(message);
|
||||||
}
|
}
|
||||||
return crypto.createHash('md5').update(new Buffer(message)).digest('hex');
|
};
|
||||||
|
return nodeMethod;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @member {Number} utf8Threshold
|
* @namespace md5.hmac
|
||||||
* @default 18
|
*/
|
||||||
* @description To use node.js md5 if UTF-8 string length is greater than this value.
|
/**
|
||||||
* @memberof md5
|
* @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');
|
||||||
*/
|
*/
|
||||||
nodeMethod.utf8Threshold = 18;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @member {Number} asciiThreshold
|
* @method digest
|
||||||
* @default 60
|
* @memberof md5.hmac
|
||||||
* @description To use node.js md5 if ascii string length is greater than this value.
|
* @description Output hash as bytes array
|
||||||
* @memberof md5
|
* @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');
|
||||||
*/
|
*/
|
||||||
nodeMethod.asciiThreshold = 60;
|
/**
|
||||||
|
* @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]();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @member {Number} bytesThreshold
|
* @method create
|
||||||
* @default 245
|
* @memberof md5.hmac
|
||||||
* @description To use node.js md5 if bytes length is greater than this value.
|
* @description Create HmacMd5 object
|
||||||
* @memberof md5
|
* @param {String|Array|Uint8Array|ArrayBuffer} key key
|
||||||
|
* @returns {HmacMd5} HmacMd5 object.
|
||||||
|
* @example
|
||||||
|
* var hash = md5.hmac.create('key');
|
||||||
*/
|
*/
|
||||||
nodeMethod.bytesThreshold = 245;
|
/**
|
||||||
return nodeMethod;
|
* @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
|
* Md5 class
|
||||||
@@ -216,7 +365,7 @@
|
|||||||
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
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.finalized = this.hashed = false;
|
||||||
this.first = true;
|
this.first = true;
|
||||||
}
|
}
|
||||||
@@ -232,13 +381,13 @@
|
|||||||
*/
|
*/
|
||||||
Md5.prototype.update = function (message) {
|
Md5.prototype.update = function (message) {
|
||||||
if (this.finalized) {
|
if (this.finalized) {
|
||||||
return;
|
throw new Error(FINALIZE_ERROR);
|
||||||
}
|
}
|
||||||
var notString = typeof(message) != 'string';
|
|
||||||
if(notString && message.constructor == root.ArrayBuffer) {
|
var result = formatMessage(message);
|
||||||
message = new Uint8Array(message);
|
message = result[0];
|
||||||
}
|
var isString = result[1];
|
||||||
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
|
var code, index = 0, i, length = message.length, blocks = this.blocks;
|
||||||
var buffer8 = this.buffer8;
|
var buffer8 = this.buffer8;
|
||||||
|
|
||||||
while (index < length) {
|
while (index < length) {
|
||||||
@@ -251,58 +400,58 @@
|
|||||||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notString) {
|
if (isString) {
|
||||||
if (ARRAY_BUFFER) {
|
if (ARRAY_BUFFER) {
|
||||||
for (i = this.start;index < length && i < 64; ++index) {
|
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 (ARRAY_BUFFER) {
|
|
||||||
for (i = this.start;index < length && i < 64; ++index) {
|
|
||||||
code = message.charCodeAt(index);
|
code = message.charCodeAt(index);
|
||||||
if (code < 0x80) {
|
if (code < 0x80) {
|
||||||
buffer8[i++] = code;
|
buffer8[i++] = code;
|
||||||
} else if (code < 0x800) {
|
} else if (code < 0x800) {
|
||||||
buffer8[i++] = 0xc0 | (code >> 6);
|
buffer8[i++] = 0xc0 | (code >>> 6);
|
||||||
buffer8[i++] = 0x80 | (code & 0x3f);
|
buffer8[i++] = 0x80 | (code & 0x3f);
|
||||||
} else if (code < 0xd800 || code >= 0xe000) {
|
} else if (code < 0xd800 || code >= 0xe000) {
|
||||||
buffer8[i++] = 0xe0 | (code >> 12);
|
buffer8[i++] = 0xe0 | (code >>> 12);
|
||||||
buffer8[i++] = 0x80 | ((code >> 6) & 0x3f);
|
buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
|
||||||
buffer8[i++] = 0x80 | (code & 0x3f);
|
buffer8[i++] = 0x80 | (code & 0x3f);
|
||||||
} else {
|
} else {
|
||||||
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
||||||
buffer8[i++] = 0xf0 | (code >> 18);
|
buffer8[i++] = 0xf0 | (code >>> 18);
|
||||||
buffer8[i++] = 0x80 | ((code >> 12) & 0x3f);
|
buffer8[i++] = 0x80 | ((code >>> 12) & 0x3f);
|
||||||
buffer8[i++] = 0x80 | ((code >> 6) & 0x3f);
|
buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
|
||||||
buffer8[i++] = 0x80 | (code & 0x3f);
|
buffer8[i++] = 0x80 | (code & 0x3f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = this.start;index < length && i < 64; ++index) {
|
for (i = this.start; index < length && i < 64; ++index) {
|
||||||
code = message.charCodeAt(index);
|
code = message.charCodeAt(index);
|
||||||
if (code < 0x80) {
|
if (code < 0x80) {
|
||||||
blocks[i >> 2] |= code << SHIFT[i++ & 3];
|
blocks[i >>> 2] |= code << SHIFT[i++ & 3];
|
||||||
} else if (code < 0x800) {
|
} else if (code < 0x800) {
|
||||||
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
|
blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3];
|
||||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||||
} else if (code < 0xd800 || code >= 0xe000) {
|
} else if (code < 0xd800 || code >= 0xe000) {
|
||||||
blocks[i >> 2] |= (0xe0 | (code >> 12)) << 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 >>> 6) & 0x3f)) << SHIFT[i++ & 3];
|
||||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||||
} else {
|
} else {
|
||||||
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
||||||
blocks[i >> 2] |= (0xf0 | (code >> 18)) << 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 >>> 12) & 0x3f)) << SHIFT[i++ & 3];
|
||||||
blocks[i >> 2] |= (0x80 | ((code >> 6) & 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] |= (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.lastByteIndex = i;
|
||||||
this.bytes += i - this.start;
|
this.bytes += i - this.start;
|
||||||
@@ -314,6 +463,10 @@
|
|||||||
this.start = i;
|
this.start = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.bytes > 4294967295) {
|
||||||
|
this.hBytes += this.bytes / 4294967296 << 0;
|
||||||
|
this.bytes = this.bytes % 4294967296;
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -323,7 +476,7 @@
|
|||||||
}
|
}
|
||||||
this.finalized = true;
|
this.finalized = true;
|
||||||
var blocks = this.blocks, i = this.lastByteIndex;
|
var blocks = this.blocks, i = this.lastByteIndex;
|
||||||
blocks[i >> 2] |= EXTRA[i & 3];
|
blocks[i >>> 2] |= EXTRA[i & 3];
|
||||||
if (i >= 56) {
|
if (i >= 56) {
|
||||||
if (!this.hashed) {
|
if (!this.hashed) {
|
||||||
this.hash();
|
this.hash();
|
||||||
@@ -335,13 +488,14 @@
|
|||||||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
||||||
}
|
}
|
||||||
blocks[14] = this.bytes << 3;
|
blocks[14] = this.bytes << 3;
|
||||||
|
blocks[15] = this.hBytes << 3 | this.bytes >>> 29;
|
||||||
this.hash();
|
this.hash();
|
||||||
};
|
};
|
||||||
|
|
||||||
Md5.prototype.hash = function () {
|
Md5.prototype.hash = function () {
|
||||||
var a, b, c, d, bc, da, blocks = this.blocks;
|
var a, b, c, d, bc, da, blocks = this.blocks;
|
||||||
|
|
||||||
if(this.first) {
|
if (this.first) {
|
||||||
a = blocks[0] - 680876937;
|
a = blocks[0] - 680876937;
|
||||||
a = (a << 7 | a >>> 25) - 271733879 << 0;
|
a = (a << 7 | a >>> 25) - 271733879 << 0;
|
||||||
d = (-1732584194 ^ a & 2004318071) + blocks[1] - 117830708;
|
d = (-1732584194 ^ a & 2004318071) + blocks[1] - 117830708;
|
||||||
@@ -494,7 +648,7 @@
|
|||||||
b += (d ^ (c | ~a)) + blocks[9] - 343485551;
|
b += (d ^ (c | ~a)) + blocks[9] - 343485551;
|
||||||
b = (b << 21 | b >>> 11) + c << 0;
|
b = (b << 21 | b >>> 11) + c << 0;
|
||||||
|
|
||||||
if(this.first) {
|
if (this.first) {
|
||||||
this.h0 = a + 1732584193 << 0;
|
this.h0 = a + 1732584193 << 0;
|
||||||
this.h1 = b - 271733879 << 0;
|
this.h1 = b - 271733879 << 0;
|
||||||
this.h2 = c - 1732584194 << 0;
|
this.h2 = c - 1732584194 << 0;
|
||||||
@@ -523,22 +677,22 @@
|
|||||||
|
|
||||||
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
|
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
|
||||||
|
|
||||||
return HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
|
return HEX_CHARS[(h0 >>> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
|
||||||
HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] +
|
HEX_CHARS[(h0 >>> 12) & 0x0F] + HEX_CHARS[(h0 >>> 8) & 0x0F] +
|
||||||
HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
|
HEX_CHARS[(h0 >>> 20) & 0x0F] + HEX_CHARS[(h0 >>> 16) & 0x0F] +
|
||||||
HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
|
HEX_CHARS[(h0 >>> 28) & 0x0F] + HEX_CHARS[(h0 >>> 24) & 0x0F] +
|
||||||
HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
|
HEX_CHARS[(h1 >>> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
|
||||||
HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] +
|
HEX_CHARS[(h1 >>> 12) & 0x0F] + HEX_CHARS[(h1 >>> 8) & 0x0F] +
|
||||||
HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] +
|
HEX_CHARS[(h1 >>> 20) & 0x0F] + HEX_CHARS[(h1 >>> 16) & 0x0F] +
|
||||||
HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] +
|
HEX_CHARS[(h1 >>> 28) & 0x0F] + HEX_CHARS[(h1 >>> 24) & 0x0F] +
|
||||||
HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
|
HEX_CHARS[(h2 >>> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
|
||||||
HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] +
|
HEX_CHARS[(h2 >>> 12) & 0x0F] + HEX_CHARS[(h2 >>> 8) & 0x0F] +
|
||||||
HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] +
|
HEX_CHARS[(h2 >>> 20) & 0x0F] + HEX_CHARS[(h2 >>> 16) & 0x0F] +
|
||||||
HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] +
|
HEX_CHARS[(h2 >>> 28) & 0x0F] + HEX_CHARS[(h2 >>> 24) & 0x0F] +
|
||||||
HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
|
HEX_CHARS[(h3 >>> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
|
||||||
HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] +
|
HEX_CHARS[(h3 >>> 12) & 0x0F] + HEX_CHARS[(h3 >>> 8) & 0x0F] +
|
||||||
HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] +
|
HEX_CHARS[(h3 >>> 20) & 0x0F] + HEX_CHARS[(h3 >>> 16) & 0x0F] +
|
||||||
HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F];
|
HEX_CHARS[(h3 >>> 28) & 0x0F] + HEX_CHARS[(h3 >>> 24) & 0x0F];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -563,15 +717,15 @@
|
|||||||
* @example
|
* @example
|
||||||
* hash.digest();
|
* hash.digest();
|
||||||
*/
|
*/
|
||||||
Md5.prototype.digest = function() {
|
Md5.prototype.digest = function () {
|
||||||
this.finalize();
|
this.finalize();
|
||||||
|
|
||||||
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
|
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
|
||||||
return [
|
return [
|
||||||
h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 24) & 0xFF,
|
h0 & 0xFF, (h0 >>> 8) & 0xFF, (h0 >>> 16) & 0xFF, (h0 >>> 24) & 0xFF,
|
||||||
h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 24) & 0xFF,
|
h1 & 0xFF, (h1 >>> 8) & 0xFF, (h1 >>> 16) & 0xFF, (h1 >>> 24) & 0xFF,
|
||||||
h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 24) & 0xFF,
|
h2 & 0xFF, (h2 >>> 8) & 0xFF, (h2 >>> 16) & 0xFF, (h2 >>> 24) & 0xFF,
|
||||||
h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 24) & 0xFF
|
h3 & 0xFF, (h3 >>> 8) & 0xFF, (h3 >>> 16) & 0xFF, (h3 >>> 24) & 0xFF
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -588,16 +742,16 @@
|
|||||||
Md5.prototype.array = Md5.prototype.digest;
|
Md5.prototype.array = Md5.prototype.digest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method buffer
|
* @method arrayBuffer
|
||||||
* @memberof Md5
|
* @memberof Md5
|
||||||
* @instance
|
* @instance
|
||||||
* @description Output hash as ArrayBuffer
|
* @description Output hash as ArrayBuffer
|
||||||
* @returns {ArrayBuffer} ArrayBuffer
|
* @returns {ArrayBuffer} ArrayBuffer
|
||||||
* @see {@link md5.buffer}
|
* @see {@link md5.arrayBuffer}
|
||||||
* @example
|
* @example
|
||||||
* hash.buffer();
|
* hash.arrayBuffer();
|
||||||
*/
|
*/
|
||||||
Md5.prototype.buffer = function() {
|
Md5.prototype.arrayBuffer = function () {
|
||||||
this.finalize();
|
this.finalize();
|
||||||
|
|
||||||
var buffer = new ArrayBuffer(16);
|
var buffer = new ArrayBuffer(16);
|
||||||
@@ -609,7 +763,116 @@
|
|||||||
return buffer;
|
return buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method buffer
|
||||||
|
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
|
||||||
|
* @memberof Md5
|
||||||
|
* @instance
|
||||||
|
* @description Output hash as ArrayBuffer
|
||||||
|
* @returns {ArrayBuffer} ArrayBuffer
|
||||||
|
* @see {@link md5.buffer}
|
||||||
|
* @example
|
||||||
|
* hash.buffer();
|
||||||
|
*/
|
||||||
|
Md5.prototype.buffer = Md5.prototype.arrayBuffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method base64
|
||||||
|
* @memberof Md5
|
||||||
|
* @instance
|
||||||
|
* @description Output hash as base64 string
|
||||||
|
* @returns {String} base64 string
|
||||||
|
* @see {@link md5.base64}
|
||||||
|
* @example
|
||||||
|
* hash.base64();
|
||||||
|
*/
|
||||||
|
Md5.prototype.base64 = function () {
|
||||||
|
var v1, v2, v3, base64Str = '', bytes = this.array();
|
||||||
|
for (var i = 0; i < 15;) {
|
||||||
|
v1 = bytes[i++];
|
||||||
|
v2 = bytes[i++];
|
||||||
|
v3 = bytes[i++];
|
||||||
|
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
|
||||||
|
BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] +
|
||||||
|
BASE64_ENCODE_CHAR[(v2 << 2 | v3 >>> 6) & 63] +
|
||||||
|
BASE64_ENCODE_CHAR[v3 & 63];
|
||||||
|
}
|
||||||
|
v1 = bytes[i];
|
||||||
|
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
|
||||||
|
BASE64_ENCODE_CHAR[(v1 << 4) & 63] +
|
||||||
|
'==';
|
||||||
|
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();
|
var exports = createMethod();
|
||||||
|
exports.md5 = exports;
|
||||||
|
exports.md5.hmac = createHmacMethod();
|
||||||
|
|
||||||
if (COMMON_JS) {
|
if (COMMON_JS) {
|
||||||
module.exports = exports;
|
module.exports = exports;
|
||||||
@@ -638,7 +901,7 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(this));
|
})();
|
||||||
</code></pre>
|
</code></pre>
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
@@ -649,13 +912,13 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav>
|
<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>
|
</nav>
|
||||||
|
|
||||||
<br class="clear">
|
<br class="clear">
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Dec 28 2015 15:48:47 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>
|
</footer>
|
||||||
|
|
||||||
<script> prettyPrint(); </script>
|
<script> prettyPrint(); </script>
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
/*global document */
|
/*global document */
|
||||||
(function() {
|
(() => {
|
||||||
var source = document.getElementsByClassName('prettyprint source linenums');
|
const source = document.getElementsByClassName('prettyprint source linenums');
|
||||||
var i = 0;
|
let i = 0;
|
||||||
var lineNumber = 0;
|
let lineNumber = 0;
|
||||||
var lineId;
|
let lineId;
|
||||||
var lines;
|
let lines;
|
||||||
var totalLines;
|
let totalLines;
|
||||||
var anchorHash;
|
let anchorHash;
|
||||||
|
|
||||||
if (source && source[0]) {
|
if (source && source[0]) {
|
||||||
anchorHash = document.location.hash.substring(1);
|
anchorHash = document.location.hash.substring(1);
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
for (; i < totalLines; i++) {
|
for (; i < totalLines; i++) {
|
||||||
lineNumber++;
|
lineNumber++;
|
||||||
lineId = 'line' + lineNumber;
|
lineId = `line${lineNumber}`;
|
||||||
lines[i].id = lineId;
|
lines[i].id = lineId;
|
||||||
if (lineId === anchorHash) {
|
if (lineId === anchorHash) {
|
||||||
lines[i].className += ' selected';
|
lines[i].className += ' selected';
|
||||||
|
|||||||
@@ -78,6 +78,10 @@ article dl {
|
|||||||
margin-bottom: 40px;
|
margin-bottom: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
article img {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
section
|
section
|
||||||
{
|
{
|
||||||
display: block;
|
display: block;
|
||||||
@@ -153,7 +157,7 @@ h1
|
|||||||
margin: 12px 24px 20px;
|
margin: 12px 24px 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h2, h3
|
h2, h3.subsection-title
|
||||||
{
|
{
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
@@ -161,6 +165,13 @@ h2, h3
|
|||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h3
|
||||||
|
{
|
||||||
|
font-size: 24px;
|
||||||
|
letter-spacing: -0.5px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
h4
|
h4
|
||||||
{
|
{
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
@@ -185,8 +196,34 @@ h6
|
|||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ancestors { color: #999; }
|
table
|
||||||
.ancestors a
|
{
|
||||||
|
border-spacing: 0;
|
||||||
|
border: 0;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
|
||||||
|
td, th
|
||||||
|
{
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
margin: 0px;
|
||||||
|
text-align: left;
|
||||||
|
vertical-align: top;
|
||||||
|
padding: 4px 6px;
|
||||||
|
display: table-cell;
|
||||||
|
}
|
||||||
|
|
||||||
|
thead tr
|
||||||
|
{
|
||||||
|
background-color: #ddd;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
th { border-right: 1px solid #aaa; }
|
||||||
|
tr > th:last-child { border-right: 1px solid #ddd; }
|
||||||
|
|
||||||
|
.ancestors, .attribs { color: #999; }
|
||||||
|
.ancestors a, .attribs a
|
||||||
{
|
{
|
||||||
color: #999 !important;
|
color: #999 !important;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
@@ -236,7 +273,7 @@ h6
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.prettyprint
|
.source
|
||||||
{
|
{
|
||||||
border: 1px solid #ddd;
|
border: 1px solid #ddd;
|
||||||
width: 80%;
|
width: 80%;
|
||||||
@@ -247,7 +284,7 @@ h6
|
|||||||
width: inherit;
|
width: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
.prettyprint code
|
.source code
|
||||||
{
|
{
|
||||||
font-size: 100%;
|
font-size: 100%;
|
||||||
line-height: 18px;
|
line-height: 18px;
|
||||||
@@ -296,44 +333,12 @@ h6
|
|||||||
user-select: text;
|
user-select: text;
|
||||||
}
|
}
|
||||||
|
|
||||||
.params, .props
|
|
||||||
{
|
|
||||||
border-spacing: 0;
|
|
||||||
border: 0;
|
|
||||||
border-collapse: collapse;
|
|
||||||
}
|
|
||||||
|
|
||||||
.params .name, .props .name, .name code {
|
.params .name, .props .name, .name code {
|
||||||
color: #4D4E53;
|
color: #4D4E53;
|
||||||
font-family: Consolas, Monaco, 'Andale Mono', monospace;
|
font-family: Consolas, Monaco, 'Andale Mono', monospace;
|
||||||
font-size: 100%;
|
font-size: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.params td, .params th, .props td, .props th
|
|
||||||
{
|
|
||||||
border: 1px solid #ddd;
|
|
||||||
margin: 0px;
|
|
||||||
text-align: left;
|
|
||||||
vertical-align: top;
|
|
||||||
padding: 4px 6px;
|
|
||||||
display: table-cell;
|
|
||||||
}
|
|
||||||
|
|
||||||
.params thead tr, .props thead tr
|
|
||||||
{
|
|
||||||
background-color: #ddd;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.params .params thead tr, .props .props thead tr
|
|
||||||
{
|
|
||||||
background-color: #fff;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.params th, .props th { border-right: 1px solid #aaa; }
|
|
||||||
.params thead .last, .props thead .last { border-right: 1px solid #ddd; }
|
|
||||||
|
|
||||||
.params td.description > p:first-child,
|
.params td.description > p:first-child,
|
||||||
.props td.description > p:first-child
|
.props td.description > p:first-child
|
||||||
{
|
{
|
||||||
|
|||||||
Vendored
+168
@@ -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;
|
||||||
Generated
+2090
File diff suppressed because it is too large
Load Diff
+21
-11
@@ -1,22 +1,23 @@
|
|||||||
{
|
{
|
||||||
"name": "js-md5",
|
"name": "js-md5",
|
||||||
"version": "0.4.0",
|
"version": "0.8.2",
|
||||||
"description": "A simple MD5 hash function for JavaScript supports UTF-8 encoding.",
|
"description": "A simple MD5 hash function for JavaScript supports UTF-8 encoding.",
|
||||||
"main": "src/md5.js",
|
"main": "build/md5.min.js",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"expect.js": "~0.3.1",
|
"expect.js": "~0.3.1",
|
||||||
"jscoverage": "~0.5.9",
|
"jsdoc": "~4.0.2",
|
||||||
"jsdoc": "^3.4.0",
|
"mocha": "~10.2.0",
|
||||||
"mocha": "~2.3.4",
|
"nyc": "^15.1.0",
|
||||||
"requirejs": "^2.1.22",
|
"requirejs": "^2.1.22",
|
||||||
"uglifyjs": "~2.4.10"
|
"tiny-worker": "^2.3.0",
|
||||||
|
"uglify-js": "^3.1.9"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha tests/node-test.js -r jscoverage",
|
"test": "nyc mocha tests/node-test.js",
|
||||||
"report": "mocha tests/node-test.js -r jscoverage --covout=html",
|
"report": "nyc --reporter=html --reporter=text mocha tests/node-test.js",
|
||||||
"coveralls": "mocha tests/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls",
|
"coveralls": "nyc report --reporter=text-lcov | coveralls",
|
||||||
"doc": "rm -rf doc;jsdoc src README.md -d doc",
|
"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"
|
"build": "npm run-script compress;npm run-script doc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -31,9 +32,18 @@
|
|||||||
"HMAC"
|
"HMAC"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "emn178 <emn178@gmail.com>",
|
"author": "Chen, Yi-Cyuan <emn178@gmail.com>",
|
||||||
"homepage": "https://github.com/emn178/js-md5",
|
"homepage": "https://github.com/emn178/js-md5",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/emn178/js-md5/issues"
|
"url": "https://github.com/emn178/js-md5/issues"
|
||||||
|
},
|
||||||
|
"nyc": {
|
||||||
|
"exclude": [
|
||||||
|
"tests"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"browser": {
|
||||||
|
"crypto": false,
|
||||||
|
"buffer": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+374
-111
@@ -2,25 +2,36 @@
|
|||||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||||
*
|
*
|
||||||
* @namespace md5
|
* @namespace md5
|
||||||
* @version 0.4.0
|
* @version 0.8.2
|
||||||
* @author Yi-Cyuan Chen [emn178@gmail.com]
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||||
* @copyright Yi-Cyuan Chen 2014-2015
|
* @copyright Chen, Yi-Cyuan 2014-2023
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
(function (root) {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var NODE_JS = typeof process == 'object' && process.versions && process.versions.node;
|
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) {
|
||||||
|
WINDOW = false;
|
||||||
|
}
|
||||||
|
var WEB_WORKER = !WINDOW && typeof self === 'object';
|
||||||
|
var NODE_JS = !root.JS_MD5_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
|
||||||
if (NODE_JS) {
|
if (NODE_JS) {
|
||||||
root = global;
|
root = global;
|
||||||
|
} else if (WEB_WORKER) {
|
||||||
|
root = self;
|
||||||
}
|
}
|
||||||
var COMMON_JS = !root.JS_MD5_TEST && typeof module == 'object' && module.exports;
|
var COMMON_JS = !root.JS_MD5_NO_COMMON_JS && typeof module === 'object' && module.exports;
|
||||||
var AMD = typeof define == 'function' && define.amd;
|
var AMD = typeof define === 'function' && define.amd;
|
||||||
var ARRAY_BUFFER = !root.JS_MD5_TEST && typeof ArrayBuffer != 'undefined';
|
var ARRAY_BUFFER = !root.JS_MD5_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
|
||||||
var HEX_CHARS = '0123456789abcdef'.split('');
|
var HEX_CHARS = '0123456789abcdef'.split('');
|
||||||
var EXTRA = [128, 32768, 8388608, -2147483648];
|
var EXTRA = [128, 32768, 8388608, -2147483648];
|
||||||
var SHIFT = [0, 8, 16, 24];
|
var SHIFT = [0, 8, 16, 24];
|
||||||
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer'];
|
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer', 'base64'];
|
||||||
|
var BASE64_ENCODE_CHAR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
|
||||||
|
|
||||||
var blocks = [], buffer8;
|
var blocks = [], buffer8;
|
||||||
if (ARRAY_BUFFER) {
|
if (ARRAY_BUFFER) {
|
||||||
@@ -29,6 +40,38 @@
|
|||||||
blocks = new Uint32Array(buffer);
|
blocks = new Uint32Array(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isArray = Array.isArray;
|
||||||
|
if (root.JS_MD5_NO_NODE_JS || !isArray) {
|
||||||
|
isArray = function (obj) {
|
||||||
|
return Object.prototype.toString.call(obj) === '[object Array]';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
* @method hex
|
||||||
* @memberof md5
|
* @memberof md5
|
||||||
@@ -58,8 +101,18 @@
|
|||||||
* @example
|
* @example
|
||||||
* md5.array('The quick brown fox jumps over the lazy dog');
|
* md5.array('The quick brown fox jumps over the lazy dog');
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* @method arrayBuffer
|
||||||
|
* @memberof md5
|
||||||
|
* @description Output hash as ArrayBuffer
|
||||||
|
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||||
|
* @returns {ArrayBuffer} ArrayBuffer
|
||||||
|
* @example
|
||||||
|
* md5.arrayBuffer('The quick brown fox jumps over the lazy dog');
|
||||||
|
*/
|
||||||
/**
|
/**
|
||||||
* @method buffer
|
* @method buffer
|
||||||
|
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
|
||||||
* @memberof md5
|
* @memberof md5
|
||||||
* @description Output hash as ArrayBuffer
|
* @description Output hash as ArrayBuffer
|
||||||
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||||
@@ -67,8 +120,17 @@
|
|||||||
* @example
|
* @example
|
||||||
* md5.buffer('The quick brown fox jumps over the lazy dog');
|
* md5.buffer('The quick brown fox jumps over the lazy dog');
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* @method base64
|
||||||
|
* @memberof md5
|
||||||
|
* @description Output hash as base64 string
|
||||||
|
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
|
||||||
|
* @returns {String} base64 string
|
||||||
|
* @example
|
||||||
|
* md5.base64('The quick brown fox jumps over the lazy dog');
|
||||||
|
*/
|
||||||
var createOutputMethod = function (outputType) {
|
var createOutputMethod = function (outputType) {
|
||||||
return function(message) {
|
return function (message) {
|
||||||
return new Md5(true).update(message)[outputType]();
|
return new Md5(true).update(message)[outputType]();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -104,7 +166,7 @@
|
|||||||
method.update = function (message) {
|
method.update = function (message) {
|
||||||
return method.create().update(message);
|
return method.create().update(message);
|
||||||
};
|
};
|
||||||
for (var i = 0;i < OUTPUT_TYPES.length;++i) {
|
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
||||||
var type = OUTPUT_TYPES[i];
|
var type = OUTPUT_TYPES[i];
|
||||||
method[type] = createOutputMethod(type);
|
method[type] = createOutputMethod(type);
|
||||||
}
|
}
|
||||||
@@ -112,57 +174,144 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
var nodeWrap = function (method) {
|
var nodeWrap = function (method) {
|
||||||
var crypto, Buffer;
|
var crypto = require('crypto')
|
||||||
try {
|
var Buffer = require('buffer').Buffer;
|
||||||
if (root.JS_MD5_TEST) {
|
var bufferFrom;
|
||||||
throw 'JS_MD5_TEST';
|
if (Buffer.from && !root.JS_MD5_NO_BUFFER_FROM) {
|
||||||
}
|
bufferFrom = Buffer.from;
|
||||||
crypto = require('crypto');
|
} else {
|
||||||
Buffer = require('buffer').Buffer;
|
bufferFrom = function (message) {
|
||||||
} catch (e) {
|
return new Buffer(message);
|
||||||
console.log(e);
|
};
|
||||||
return method;
|
|
||||||
}
|
}
|
||||||
var nodeMethod = function (message) {
|
var nodeMethod = function (message) {
|
||||||
if (typeof message == 'string') {
|
if (typeof message === 'string') {
|
||||||
if (message.length <= nodeMethod.utf8Threshold) {
|
|
||||||
return method(message);
|
|
||||||
} else if (message.length <= nodeMethod.asciiThreshold && !/[^\x00-\x7F]/.test(message)) {
|
|
||||||
return method(message);
|
|
||||||
}
|
|
||||||
return crypto.createHash('md5').update(message, 'utf8').digest('hex');
|
return crypto.createHash('md5').update(message, 'utf8').digest('hex');
|
||||||
} else if (message.constructor == ArrayBuffer) {
|
} else {
|
||||||
|
if (message === null || message === undefined) {
|
||||||
|
throw new Error(INPUT_ERROR);
|
||||||
|
} else if (message.constructor === ArrayBuffer) {
|
||||||
message = new Uint8Array(message);
|
message = new Uint8Array(message);
|
||||||
} else if (message.length === undefined || message.length <= nodeMethod.bytesThreshold) {
|
}
|
||||||
|
}
|
||||||
|
if (isArray(message) || isView(message) ||
|
||||||
|
message.constructor === Buffer) {
|
||||||
|
return crypto.createHash('md5').update(bufferFrom(message)).digest('hex');
|
||||||
|
} else {
|
||||||
return method(message);
|
return method(message);
|
||||||
}
|
}
|
||||||
return crypto.createHash('md5').update(new Buffer(message)).digest('hex');
|
};
|
||||||
|
return nodeMethod;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @member {Number} utf8Threshold
|
* @namespace md5.hmac
|
||||||
* @default 18
|
*/
|
||||||
* @description To use node.js md5 if UTF-8 string length is greater than this value.
|
/**
|
||||||
* @memberof md5
|
* @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');
|
||||||
*/
|
*/
|
||||||
nodeMethod.utf8Threshold = 18;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @member {Number} asciiThreshold
|
* @method digest
|
||||||
* @default 60
|
* @memberof md5.hmac
|
||||||
* @description To use node.js md5 if ascii string length is greater than this value.
|
* @description Output hash as bytes array
|
||||||
* @memberof md5
|
* @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');
|
||||||
*/
|
*/
|
||||||
nodeMethod.asciiThreshold = 60;
|
/**
|
||||||
|
* @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]();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @member {Number} bytesThreshold
|
* @method create
|
||||||
* @default 245
|
* @memberof md5.hmac
|
||||||
* @description To use node.js md5 if bytes length is greater than this value.
|
* @description Create HmacMd5 object
|
||||||
* @memberof md5
|
* @param {String|Array|Uint8Array|ArrayBuffer} key key
|
||||||
|
* @returns {HmacMd5} HmacMd5 object.
|
||||||
|
* @example
|
||||||
|
* var hash = md5.hmac.create('key');
|
||||||
*/
|
*/
|
||||||
nodeMethod.bytesThreshold = 245;
|
/**
|
||||||
return nodeMethod;
|
* @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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -188,7 +337,7 @@
|
|||||||
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
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.finalized = this.hashed = false;
|
||||||
this.first = true;
|
this.first = true;
|
||||||
}
|
}
|
||||||
@@ -204,13 +353,13 @@
|
|||||||
*/
|
*/
|
||||||
Md5.prototype.update = function (message) {
|
Md5.prototype.update = function (message) {
|
||||||
if (this.finalized) {
|
if (this.finalized) {
|
||||||
return;
|
throw new Error(FINALIZE_ERROR);
|
||||||
}
|
}
|
||||||
var notString = typeof(message) != 'string';
|
|
||||||
if(notString && message.constructor == root.ArrayBuffer) {
|
var result = formatMessage(message);
|
||||||
message = new Uint8Array(message);
|
message = result[0];
|
||||||
}
|
var isString = result[1];
|
||||||
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
|
var code, index = 0, i, length = message.length, blocks = this.blocks;
|
||||||
var buffer8 = this.buffer8;
|
var buffer8 = this.buffer8;
|
||||||
|
|
||||||
while (index < length) {
|
while (index < length) {
|
||||||
@@ -223,58 +372,58 @@
|
|||||||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notString) {
|
if (isString) {
|
||||||
if (ARRAY_BUFFER) {
|
if (ARRAY_BUFFER) {
|
||||||
for (i = this.start;index < length && i < 64; ++index) {
|
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 (ARRAY_BUFFER) {
|
|
||||||
for (i = this.start;index < length && i < 64; ++index) {
|
|
||||||
code = message.charCodeAt(index);
|
code = message.charCodeAt(index);
|
||||||
if (code < 0x80) {
|
if (code < 0x80) {
|
||||||
buffer8[i++] = code;
|
buffer8[i++] = code;
|
||||||
} else if (code < 0x800) {
|
} else if (code < 0x800) {
|
||||||
buffer8[i++] = 0xc0 | (code >> 6);
|
buffer8[i++] = 0xc0 | (code >>> 6);
|
||||||
buffer8[i++] = 0x80 | (code & 0x3f);
|
buffer8[i++] = 0x80 | (code & 0x3f);
|
||||||
} else if (code < 0xd800 || code >= 0xe000) {
|
} else if (code < 0xd800 || code >= 0xe000) {
|
||||||
buffer8[i++] = 0xe0 | (code >> 12);
|
buffer8[i++] = 0xe0 | (code >>> 12);
|
||||||
buffer8[i++] = 0x80 | ((code >> 6) & 0x3f);
|
buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
|
||||||
buffer8[i++] = 0x80 | (code & 0x3f);
|
buffer8[i++] = 0x80 | (code & 0x3f);
|
||||||
} else {
|
} else {
|
||||||
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
||||||
buffer8[i++] = 0xf0 | (code >> 18);
|
buffer8[i++] = 0xf0 | (code >>> 18);
|
||||||
buffer8[i++] = 0x80 | ((code >> 12) & 0x3f);
|
buffer8[i++] = 0x80 | ((code >>> 12) & 0x3f);
|
||||||
buffer8[i++] = 0x80 | ((code >> 6) & 0x3f);
|
buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
|
||||||
buffer8[i++] = 0x80 | (code & 0x3f);
|
buffer8[i++] = 0x80 | (code & 0x3f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = this.start;index < length && i < 64; ++index) {
|
for (i = this.start; index < length && i < 64; ++index) {
|
||||||
code = message.charCodeAt(index);
|
code = message.charCodeAt(index);
|
||||||
if (code < 0x80) {
|
if (code < 0x80) {
|
||||||
blocks[i >> 2] |= code << SHIFT[i++ & 3];
|
blocks[i >>> 2] |= code << SHIFT[i++ & 3];
|
||||||
} else if (code < 0x800) {
|
} else if (code < 0x800) {
|
||||||
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
|
blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3];
|
||||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||||
} else if (code < 0xd800 || code >= 0xe000) {
|
} else if (code < 0xd800 || code >= 0xe000) {
|
||||||
blocks[i >> 2] |= (0xe0 | (code >> 12)) << 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 >>> 6) & 0x3f)) << SHIFT[i++ & 3];
|
||||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||||
} else {
|
} else {
|
||||||
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
||||||
blocks[i >> 2] |= (0xf0 | (code >> 18)) << 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 >>> 12) & 0x3f)) << SHIFT[i++ & 3];
|
||||||
blocks[i >> 2] |= (0x80 | ((code >> 6) & 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] |= (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.lastByteIndex = i;
|
||||||
this.bytes += i - this.start;
|
this.bytes += i - this.start;
|
||||||
@@ -286,6 +435,10 @@
|
|||||||
this.start = i;
|
this.start = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.bytes > 4294967295) {
|
||||||
|
this.hBytes += this.bytes / 4294967296 << 0;
|
||||||
|
this.bytes = this.bytes % 4294967296;
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -295,7 +448,7 @@
|
|||||||
}
|
}
|
||||||
this.finalized = true;
|
this.finalized = true;
|
||||||
var blocks = this.blocks, i = this.lastByteIndex;
|
var blocks = this.blocks, i = this.lastByteIndex;
|
||||||
blocks[i >> 2] |= EXTRA[i & 3];
|
blocks[i >>> 2] |= EXTRA[i & 3];
|
||||||
if (i >= 56) {
|
if (i >= 56) {
|
||||||
if (!this.hashed) {
|
if (!this.hashed) {
|
||||||
this.hash();
|
this.hash();
|
||||||
@@ -307,13 +460,14 @@
|
|||||||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
||||||
}
|
}
|
||||||
blocks[14] = this.bytes << 3;
|
blocks[14] = this.bytes << 3;
|
||||||
|
blocks[15] = this.hBytes << 3 | this.bytes >>> 29;
|
||||||
this.hash();
|
this.hash();
|
||||||
};
|
};
|
||||||
|
|
||||||
Md5.prototype.hash = function () {
|
Md5.prototype.hash = function () {
|
||||||
var a, b, c, d, bc, da, blocks = this.blocks;
|
var a, b, c, d, bc, da, blocks = this.blocks;
|
||||||
|
|
||||||
if(this.first) {
|
if (this.first) {
|
||||||
a = blocks[0] - 680876937;
|
a = blocks[0] - 680876937;
|
||||||
a = (a << 7 | a >>> 25) - 271733879 << 0;
|
a = (a << 7 | a >>> 25) - 271733879 << 0;
|
||||||
d = (-1732584194 ^ a & 2004318071) + blocks[1] - 117830708;
|
d = (-1732584194 ^ a & 2004318071) + blocks[1] - 117830708;
|
||||||
@@ -466,7 +620,7 @@
|
|||||||
b += (d ^ (c | ~a)) + blocks[9] - 343485551;
|
b += (d ^ (c | ~a)) + blocks[9] - 343485551;
|
||||||
b = (b << 21 | b >>> 11) + c << 0;
|
b = (b << 21 | b >>> 11) + c << 0;
|
||||||
|
|
||||||
if(this.first) {
|
if (this.first) {
|
||||||
this.h0 = a + 1732584193 << 0;
|
this.h0 = a + 1732584193 << 0;
|
||||||
this.h1 = b - 271733879 << 0;
|
this.h1 = b - 271733879 << 0;
|
||||||
this.h2 = c - 1732584194 << 0;
|
this.h2 = c - 1732584194 << 0;
|
||||||
@@ -495,22 +649,22 @@
|
|||||||
|
|
||||||
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
|
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
|
||||||
|
|
||||||
return HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
|
return HEX_CHARS[(h0 >>> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
|
||||||
HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] +
|
HEX_CHARS[(h0 >>> 12) & 0x0F] + HEX_CHARS[(h0 >>> 8) & 0x0F] +
|
||||||
HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
|
HEX_CHARS[(h0 >>> 20) & 0x0F] + HEX_CHARS[(h0 >>> 16) & 0x0F] +
|
||||||
HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
|
HEX_CHARS[(h0 >>> 28) & 0x0F] + HEX_CHARS[(h0 >>> 24) & 0x0F] +
|
||||||
HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
|
HEX_CHARS[(h1 >>> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
|
||||||
HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] +
|
HEX_CHARS[(h1 >>> 12) & 0x0F] + HEX_CHARS[(h1 >>> 8) & 0x0F] +
|
||||||
HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] +
|
HEX_CHARS[(h1 >>> 20) & 0x0F] + HEX_CHARS[(h1 >>> 16) & 0x0F] +
|
||||||
HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] +
|
HEX_CHARS[(h1 >>> 28) & 0x0F] + HEX_CHARS[(h1 >>> 24) & 0x0F] +
|
||||||
HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
|
HEX_CHARS[(h2 >>> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
|
||||||
HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] +
|
HEX_CHARS[(h2 >>> 12) & 0x0F] + HEX_CHARS[(h2 >>> 8) & 0x0F] +
|
||||||
HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] +
|
HEX_CHARS[(h2 >>> 20) & 0x0F] + HEX_CHARS[(h2 >>> 16) & 0x0F] +
|
||||||
HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] +
|
HEX_CHARS[(h2 >>> 28) & 0x0F] + HEX_CHARS[(h2 >>> 24) & 0x0F] +
|
||||||
HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
|
HEX_CHARS[(h3 >>> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
|
||||||
HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] +
|
HEX_CHARS[(h3 >>> 12) & 0x0F] + HEX_CHARS[(h3 >>> 8) & 0x0F] +
|
||||||
HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] +
|
HEX_CHARS[(h3 >>> 20) & 0x0F] + HEX_CHARS[(h3 >>> 16) & 0x0F] +
|
||||||
HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F];
|
HEX_CHARS[(h3 >>> 28) & 0x0F] + HEX_CHARS[(h3 >>> 24) & 0x0F];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -535,15 +689,15 @@
|
|||||||
* @example
|
* @example
|
||||||
* hash.digest();
|
* hash.digest();
|
||||||
*/
|
*/
|
||||||
Md5.prototype.digest = function() {
|
Md5.prototype.digest = function () {
|
||||||
this.finalize();
|
this.finalize();
|
||||||
|
|
||||||
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
|
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
|
||||||
return [
|
return [
|
||||||
h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 24) & 0xFF,
|
h0 & 0xFF, (h0 >>> 8) & 0xFF, (h0 >>> 16) & 0xFF, (h0 >>> 24) & 0xFF,
|
||||||
h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 24) & 0xFF,
|
h1 & 0xFF, (h1 >>> 8) & 0xFF, (h1 >>> 16) & 0xFF, (h1 >>> 24) & 0xFF,
|
||||||
h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 24) & 0xFF,
|
h2 & 0xFF, (h2 >>> 8) & 0xFF, (h2 >>> 16) & 0xFF, (h2 >>> 24) & 0xFF,
|
||||||
h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 24) & 0xFF
|
h3 & 0xFF, (h3 >>> 8) & 0xFF, (h3 >>> 16) & 0xFF, (h3 >>> 24) & 0xFF
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -560,16 +714,16 @@
|
|||||||
Md5.prototype.array = Md5.prototype.digest;
|
Md5.prototype.array = Md5.prototype.digest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method buffer
|
* @method arrayBuffer
|
||||||
* @memberof Md5
|
* @memberof Md5
|
||||||
* @instance
|
* @instance
|
||||||
* @description Output hash as ArrayBuffer
|
* @description Output hash as ArrayBuffer
|
||||||
* @returns {ArrayBuffer} ArrayBuffer
|
* @returns {ArrayBuffer} ArrayBuffer
|
||||||
* @see {@link md5.buffer}
|
* @see {@link md5.arrayBuffer}
|
||||||
* @example
|
* @example
|
||||||
* hash.buffer();
|
* hash.arrayBuffer();
|
||||||
*/
|
*/
|
||||||
Md5.prototype.buffer = function() {
|
Md5.prototype.arrayBuffer = function () {
|
||||||
this.finalize();
|
this.finalize();
|
||||||
|
|
||||||
var buffer = new ArrayBuffer(16);
|
var buffer = new ArrayBuffer(16);
|
||||||
@@ -581,7 +735,116 @@
|
|||||||
return buffer;
|
return buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method buffer
|
||||||
|
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
|
||||||
|
* @memberof Md5
|
||||||
|
* @instance
|
||||||
|
* @description Output hash as ArrayBuffer
|
||||||
|
* @returns {ArrayBuffer} ArrayBuffer
|
||||||
|
* @see {@link md5.buffer}
|
||||||
|
* @example
|
||||||
|
* hash.buffer();
|
||||||
|
*/
|
||||||
|
Md5.prototype.buffer = Md5.prototype.arrayBuffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method base64
|
||||||
|
* @memberof Md5
|
||||||
|
* @instance
|
||||||
|
* @description Output hash as base64 string
|
||||||
|
* @returns {String} base64 string
|
||||||
|
* @see {@link md5.base64}
|
||||||
|
* @example
|
||||||
|
* hash.base64();
|
||||||
|
*/
|
||||||
|
Md5.prototype.base64 = function () {
|
||||||
|
var v1, v2, v3, base64Str = '', bytes = this.array();
|
||||||
|
for (var i = 0; i < 15;) {
|
||||||
|
v1 = bytes[i++];
|
||||||
|
v2 = bytes[i++];
|
||||||
|
v3 = bytes[i++];
|
||||||
|
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
|
||||||
|
BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] +
|
||||||
|
BASE64_ENCODE_CHAR[(v2 << 2 | v3 >>> 6) & 63] +
|
||||||
|
BASE64_ENCODE_CHAR[v3 & 63];
|
||||||
|
}
|
||||||
|
v1 = bytes[i];
|
||||||
|
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
|
||||||
|
BASE64_ENCODE_CHAR[(v1 << 4) & 63] +
|
||||||
|
'==';
|
||||||
|
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();
|
var exports = createMethod();
|
||||||
|
exports.md5 = exports;
|
||||||
|
exports.md5.hmac = createHmacMethod();
|
||||||
|
|
||||||
if (COMMON_JS) {
|
if (COMMON_JS) {
|
||||||
module.exports = exports;
|
module.exports = exports;
|
||||||
@@ -610,4 +873,4 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(this));
|
})();
|
||||||
|
|||||||
@@ -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');
|
mocha.setup('bdd');
|
||||||
</script>
|
</script>
|
||||||
<script src="test.js"></script>
|
<script src="test.js"></script>
|
||||||
|
<script src="hmac-test.js"></script>
|
||||||
<script>
|
<script>
|
||||||
mocha.checkLeaks();
|
mocha.checkLeaks();
|
||||||
mocha.run();
|
mocha.run();
|
||||||
|
|||||||
+97
-12
@@ -1,23 +1,108 @@
|
|||||||
md5 = require('../src/md5.js');
|
|
||||||
expect = require('expect.js');
|
expect = require('expect.js');
|
||||||
require('./test.js');
|
Worker = require("tiny-worker");
|
||||||
|
|
||||||
delete require.cache[require.resolve('../src/md5.js')]
|
function unset() {
|
||||||
delete require.cache[require.resolve('./test.js')]
|
delete require.cache[require.resolve('../src/md5.js')];
|
||||||
md5 = null
|
delete require.cache[require.resolve('./test.js')];
|
||||||
|
delete require.cache[require.resolve('./hmac-test.js')];
|
||||||
|
md5 = null;
|
||||||
|
BUFFER = undefined;
|
||||||
|
JS_MD5_NO_WINDOW = undefined;
|
||||||
|
JS_MD5_NO_NODE_JS = undefined;
|
||||||
|
JS_MD5_NO_COMMON_JS = undefined;
|
||||||
|
JS_MD5_NO_ARRAY_BUFFER = undefined;
|
||||||
|
JS_MD5_NO_ARRAY_BUFFER_IS_VIEW = undefined;
|
||||||
|
window = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
JS_MD5_TEST = true;
|
function runCommonJsTest() {
|
||||||
require('../src/md5.js');
|
md5 = require('../src/md5.js');
|
||||||
require('./test.js');
|
require('./test.js');
|
||||||
|
require('./hmac-test.js');
|
||||||
|
unset();
|
||||||
|
}
|
||||||
|
|
||||||
delete require.cache[require.resolve('../src/md5.js')];
|
function runWindowTest() {
|
||||||
delete require.cache[require.resolve('./test.js')];
|
window = global;
|
||||||
md5 = null;
|
require('../src/md5.js');
|
||||||
|
require('./test.js');
|
||||||
|
require('./hmac-test.js');
|
||||||
|
unset();
|
||||||
|
}
|
||||||
|
|
||||||
define = function(func) {
|
// Node.js env
|
||||||
|
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();
|
||||||
|
|
||||||
|
// browser env
|
||||||
|
JS_MD5_NO_NODE_JS = true;
|
||||||
|
JS_MD5_NO_COMMON_JS = true;
|
||||||
|
runWindowTest();
|
||||||
|
|
||||||
|
// browser env and no array buffer
|
||||||
|
JS_MD5_NO_NODE_JS = true;
|
||||||
|
JS_MD5_NO_COMMON_JS = true;
|
||||||
|
JS_MD5_NO_ARRAY_BUFFER = true;
|
||||||
|
runWindowTest();
|
||||||
|
|
||||||
|
// browser env and no isView
|
||||||
|
JS_MD5_NO_NODE_JS = true;
|
||||||
|
JS_MD5_NO_COMMON_JS = true;
|
||||||
|
JS_MD5_NO_ARRAY_BUFFER_IS_VIEW = true;
|
||||||
|
runWindowTest();
|
||||||
|
|
||||||
|
// browser AMD
|
||||||
|
JS_MD5_NO_NODE_JS = true;
|
||||||
|
JS_MD5_NO_COMMON_JS = true;
|
||||||
|
window = global;
|
||||||
|
define = function (func) {
|
||||||
md5 = func();
|
md5 = func();
|
||||||
require('./test.js');
|
require('./test.js');
|
||||||
|
require('./hmac-test.js');
|
||||||
};
|
};
|
||||||
define.amd = true;
|
define.amd = true;
|
||||||
|
|
||||||
require('../src/md5.js');
|
require('../src/md5.js');
|
||||||
|
unset();
|
||||||
|
|
||||||
|
// webworker
|
||||||
|
WORKER = 'tests/worker.js';
|
||||||
|
SOURCE = 'src/md5.js';
|
||||||
|
|
||||||
|
require('./worker-test.js');
|
||||||
|
|
||||||
|
delete require.cache[require.resolve('./worker-test.js')];
|
||||||
|
|
||||||
|
// cover webworker
|
||||||
|
JS_MD5_NO_WINDOW = true;
|
||||||
|
JS_MD5_NO_NODE_JS = true;
|
||||||
|
WORKER = './worker.js';
|
||||||
|
SOURCE = '../src/md5.js';
|
||||||
|
window = global;
|
||||||
|
self = global;
|
||||||
|
|
||||||
|
Worker = function (file) {
|
||||||
|
require(file);
|
||||||
|
currentWorker = this;
|
||||||
|
|
||||||
|
this.postMessage = function (data) {
|
||||||
|
onmessage({data: data});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
postMessage = function (data) {
|
||||||
|
currentWorker.onmessage({data: data});
|
||||||
|
}
|
||||||
|
|
||||||
|
importScripts = function () {};
|
||||||
|
|
||||||
|
md5 = require('../src/md5.js');
|
||||||
|
require('./worker-test.js');
|
||||||
|
|||||||
@@ -12,12 +12,12 @@
|
|||||||
<div id="mocha"></div>
|
<div id="mocha"></div>
|
||||||
<script>
|
<script>
|
||||||
mocha.setup('bdd');
|
mocha.setup('bdd');
|
||||||
require(['../src/md5.js'], function(md5) {
|
require(['../src/md5.js'], function (md5) {
|
||||||
window.md5 = md5;
|
window.md5 = md5;
|
||||||
require(['test.js'], function() {
|
require(['test.js', 'hmac-test.js'], function () {
|
||||||
mocha.checkLeaks();
|
mocha.checkLeaks();
|
||||||
mocha.run();
|
mocha.run();
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
+115
-82
@@ -2,7 +2,7 @@
|
|||||||
Array.prototype.toHexString = ArrayBuffer.prototype.toHexString = function () {
|
Array.prototype.toHexString = ArrayBuffer.prototype.toHexString = function () {
|
||||||
var array = new Uint8Array(this);
|
var array = new Uint8Array(this);
|
||||||
var hex = '';
|
var hex = '';
|
||||||
for (var i = 0;i < array.length;++i) {
|
for (var i = 0; i < array.length; ++i) {
|
||||||
var c = array[i].toString('16');
|
var c = array[i].toString('16');
|
||||||
hex += c.length == 1 ? '0' + c : c;
|
hex += c.length == 1 ? '0' + c : c;
|
||||||
}
|
}
|
||||||
@@ -42,22 +42,67 @@
|
|||||||
'd41d8cd98f00b204e9800998ecf8427e': [],
|
'd41d8cd98f00b204e9800998ecf8427e': [],
|
||||||
'93b885adfe0da089cdf634904fd59f71': [0],
|
'93b885adfe0da089cdf634904fd59f71': [0],
|
||||||
'9e107d9d372bb6826bd81d3542a419d6': [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]
|
'9e107d9d372bb6826bd81d3542a419d6': [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]
|
||||||
},
|
|
||||||
'Uint8Array': {
|
|
||||||
'9e107d9d372bb6826bd81d3542a419d6': 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])
|
|
||||||
},
|
|
||||||
'Int8Array': {
|
|
||||||
'9e107d9d372bb6826bd81d3542a419d6': new Int8Array([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])
|
|
||||||
},
|
|
||||||
'ArrayBuffer': {
|
|
||||||
'93b885adfe0da089cdf634904fd59f71': new ArrayBuffer(1)
|
|
||||||
},
|
|
||||||
'Object': {
|
|
||||||
'd41d8cd98f00b204e9800998ecf8427e': {},
|
|
||||||
'd41d8cd98f00b204e9800998ecf8427e': {what: 'ever'}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var base64TestCases = {
|
||||||
|
'ascii': {
|
||||||
|
'1B2M2Y8AsgTpgAmY7PhCfg==': '',
|
||||||
|
'nhB9nTcrtoJr2B01QqQZ1g==': 'The quick brown fox jumps over the lazy dog',
|
||||||
|
'5NkJwpDQ+xygaP+t3yLL0A==': 'The quick brown fox jumps over the lazy dog.'
|
||||||
|
},
|
||||||
|
'ascii more than 64 bytes': {
|
||||||
|
'9jhy73vJeoqOrbpvCIHeUw==': 'The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.'
|
||||||
|
},
|
||||||
|
'UTF8': {
|
||||||
|
'p7rCI5/NyzoGeQPYB3xKBw==': '中文',
|
||||||
|
'7D7b87BaRJ/CBqATjHOcOw==': 'aécio',
|
||||||
|
'uQhpqvEhIQ9sVjlz+oVWUA==': '𠜎'
|
||||||
|
},
|
||||||
|
'UTF8 more than 64 bytes': {
|
||||||
|
'7c5hWxeebim+IxRbd+u9YQ==': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一',
|
||||||
|
'rTbJq2aaC6nORtPOkTTeNA==': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。'
|
||||||
|
},
|
||||||
|
'special length': {
|
||||||
|
'oRneY+SyOYQn2gbdeAJjsw==': '0123456780123456780123456780123456780123456780123456780',
|
||||||
|
'3a/YTr5jrrxGJrA3pWnXiw==': '01234567801234567801234567801234567801234567801234567801',
|
||||||
|
'nqBNdDYYeXzkZERbV4WmMA==': '0123456780123456780123456780123456780123456780123456780123456780',
|
||||||
|
'ZY2RSuQsSTiHSy54bM2keQ==': '01234567801234567801234567801234567801234567801234567801234567801234567',
|
||||||
|
'oIOjcQ1oV5Px8XmIv+PBdQ==': '012345678012345678012345678012345678012345678012345678012345678012345678',
|
||||||
|
'KyGoQ8/DHIAmoNg1vJG8mA==': '012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678',
|
||||||
|
'0C696XkmTHnhQVWfyfa2XA==': '012345678901234567',
|
||||||
|
'HO2BGvR+rTdIcvzKnXPdcQ==': '012345678901234567890123456789012345678901234567890123456789',
|
||||||
|
'/7gaJDpg2sRZKTAIc+BShw==': '012345678901234567中文',
|
||||||
|
},
|
||||||
|
'Array': {
|
||||||
|
'1B2M2Y8AsgTpgAmY7PhCfg==': [],
|
||||||
|
'k7iFrf4NoInN9jSQT9WfcQ==': [0],
|
||||||
|
'nhB9nTcrtoJr2B01QqQZ1g==': [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]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!(typeof JS_MD5_NO_ARRAY_BUFFER === 'boolean' && JS_MD5_NO_ARRAY_BUFFER)) {
|
||||||
|
testCases['Uint8Array'] = {
|
||||||
|
'9e107d9d372bb6826bd81d3542a419d6': 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])
|
||||||
|
};
|
||||||
|
testCases['Int8Array'] = {
|
||||||
|
'9e107d9d372bb6826bd81d3542a419d6': new Int8Array([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])
|
||||||
|
};
|
||||||
|
testCases['ArrayBuffer'] = {
|
||||||
|
'93b885adfe0da089cdf634904fd59f71': new ArrayBuffer(1)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof BUFFER === 'boolean' && BUFFER) {
|
||||||
|
testCases['Buffer'] = {
|
||||||
|
'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]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var errorTestCases = [null, undefined, { length: 0 }, 0, 1, false, true, NaN, Infinity, function () {}];
|
||||||
|
|
||||||
var methods = [
|
var methods = [
|
||||||
{
|
{
|
||||||
name: 'md5',
|
name: 'md5',
|
||||||
@@ -79,6 +124,12 @@
|
|||||||
return md5.digest(message).toHexString();
|
return md5.digest(message).toHexString();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'md5.arrayBuffer',
|
||||||
|
call: function (message) {
|
||||||
|
return md5.arrayBuffer(message).toHexString();
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'md5.buffer',
|
name: 'md5.buffer',
|
||||||
call: function (message) {
|
call: function (message) {
|
||||||
@@ -118,6 +169,12 @@
|
|||||||
return md5.update(message).digest().toHexString();
|
return md5.update(message).digest().toHexString();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'arrayBuffer',
|
||||||
|
call: function (message) {
|
||||||
|
return md5.update(message).arrayBuffer().toHexString();
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'buffer',
|
name: 'buffer',
|
||||||
call: function (message) {
|
call: function (message) {
|
||||||
@@ -129,12 +186,12 @@
|
|||||||
call: function (message) {
|
call: function (message) {
|
||||||
var hash = md5.update(message);
|
var hash = md5.update(message);
|
||||||
hash.hex();
|
hash.hex();
|
||||||
hash.update(message);
|
|
||||||
return hash.hex();
|
return hash.hex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
describe('md5', function () {
|
||||||
methods.forEach(function (method) {
|
methods.forEach(function (method) {
|
||||||
describe('#' + method.name, function () {
|
describe('#' + method.name, function () {
|
||||||
for (var testCaseName in testCases) {
|
for (var testCaseName in testCases) {
|
||||||
@@ -154,7 +211,6 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Md5', function () {
|
|
||||||
classMethods.forEach(function (method) {
|
classMethods.forEach(function (method) {
|
||||||
describe('#' + method.name, function () {
|
describe('#' + method.name, function () {
|
||||||
for (var testCaseName in testCases) {
|
for (var testCaseName in testCases) {
|
||||||
@@ -173,74 +229,51 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#md5', function () {
|
||||||
|
errorTestCases.forEach(function (testCase) {
|
||||||
|
context('when ' + testCase, function () {
|
||||||
|
it('should throw error', function () {
|
||||||
|
expect(function () {
|
||||||
|
md5(testCase);
|
||||||
|
}).to.throwError(/input is invalid type/);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
// describe('md5', function() {
|
|
||||||
// describe('ascii', function() {
|
|
||||||
// describe('less than 64 bytes', function() {
|
|
||||||
// it('should be successful', function() {
|
|
||||||
// expect(md5('')).to.be('d41d8cd98f00b204e9800998ecf8427e');
|
|
||||||
// expect(md5('The quick brown fox jumps over the lazy dog')).to.be('9e107d9d372bb6826bd81d3542a419d6');
|
|
||||||
// expect(md5('The quick brown fox jumps over the lazy dog.')).to.be('e4d909c290d0fb1ca068ffaddf22cbd0');
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// describe('more than 64 bytes', function() {
|
context('when update after finalize', function () {
|
||||||
// it('should be successful', function() {
|
it('should throw error', function () {
|
||||||
// expect(md5('The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.')).to.be('f63872ef7bc97a8a8eadba6f0881de53');
|
expect(function () {
|
||||||
// });
|
var hash = md5.update('any');
|
||||||
// });
|
hash.hex();
|
||||||
// });
|
hash.update('any');
|
||||||
|
}).to.throwError(/finalize already called/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// describe('UTF8', function() {
|
context('when large size', function () {
|
||||||
// describe('less than 64 bytes', function() {
|
var hash = md5.create();
|
||||||
// it('should be successful', function() {
|
hash.bytes = 4294967295;
|
||||||
// expect(md5('中文')).to.be('a7bac2239fcdcb3a067903d8077c4a07');
|
hash.update('any');
|
||||||
// expect(md5('aécio')).to.be('ec3edbf3b05a449fc206a0138c739c3b');
|
expect(hash.hBytes).to.be(1);
|
||||||
// expect(md5('𠜎')).to.be('b90869aaf121210f6c563973fa855650');
|
});
|
||||||
// });
|
});
|
||||||
// });
|
|
||||||
|
|
||||||
// describe('more than 64 bytes', function() {
|
describe('#bas64', function () {
|
||||||
// it('should be successful', function() {
|
for (var testCaseName in base64TestCases) {
|
||||||
// expect(md5('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('edce615b179e6e29be23145b77ebbd61');
|
var testCase = base64TestCases[testCaseName];
|
||||||
// expect(md5('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('ad36c9ab669a0ba9ce46d3ce9134de34');
|
context('when ' + testCaseName, function () {
|
||||||
// });
|
for (var hash in testCase) {
|
||||||
// });
|
(function (message, hash) {
|
||||||
// });
|
it('should be equal', function () {
|
||||||
|
expect(md5.base64(message)).to.be(hash);
|
||||||
// describe('special length', function() {
|
expect(md5.create().update(message).base64()).to.be(hash);
|
||||||
// it('should be successful', function() {
|
expect(md5.update(message).base64()).to.be(hash);
|
||||||
// expect(md5('0123456780123456780123456780123456780123456780123456780')).to.be('a119de63e4b2398427da06dd780263b3');
|
});
|
||||||
// expect(md5('01234567801234567801234567801234567801234567801234567801')).to.be('ddafd84ebe63aebc4626b037a569d78b');
|
})(testCase[hash], hash);
|
||||||
// expect(md5('0123456780123456780123456780123456780123456780123456780123456780')).to.be('9ea04d743618797ce464445b5785a630');
|
}
|
||||||
// expect(md5('01234567801234567801234567801234567801234567801234567801234567801234567')).to.be('658d914ae42c4938874b2e786ccda479');
|
});
|
||||||
// expect(md5('012345678012345678012345678012345678012345678012345678012345678012345678')).to.be('a083a3710d685793f1f17988bfe3c175');
|
}
|
||||||
// expect(md5('012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678012345678')).to.be('2b21a843cfc31c8026a0d835bc91bc98');
|
});
|
||||||
// });
|
});
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// describe('Array', function() {
|
|
||||||
// describe('Array', function() {
|
|
||||||
// it('should be successful', function() {
|
|
||||||
// expect(md5([])).to.be('d41d8cd98f00b204e9800998ecf8427e');
|
|
||||||
// expect(md5([0])).to.be('93b885adfe0da089cdf634904fd59f71');
|
|
||||||
// expect(md5([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])).to.be('9e107d9d372bb6826bd81d3542a419d6');
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// describe('Uint8Array', function() {
|
|
||||||
// it('should be successful', function() {
|
|
||||||
// expect(md5(new Uint8Array([]))).to.be('d41d8cd98f00b204e9800998ecf8427e');
|
|
||||||
// expect(md5(new Uint8Array(371))).to.be('58f494c2a0fb65332110fb62ae5c4a74');
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// describe('ArrayBuffer', function() {
|
|
||||||
// it('should be successful', function() {
|
|
||||||
// expect(md5(new ArrayBuffer(0))).to.be('d41d8cd98f00b204e9800998ecf8427e');
|
|
||||||
// expect(md5(new ArrayBuffer(1))).to.be('93b885adfe0da089cdf634904fd59f71');
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
})(md5);
|
})(md5);
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
(function (Worker, WORKER, SOURCE) {
|
||||||
|
var cases = {
|
||||||
|
'd41d8cd98f00b204e9800998ecf8427e': '',
|
||||||
|
'9e107d9d372bb6826bd81d3542a419d6': 'The quick brown fox jumps over the lazy dog',
|
||||||
|
'e4d909c290d0fb1ca068ffaddf22cbd0': 'The quick brown fox jumps over the lazy dog.'
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('#md5', function () {
|
||||||
|
Object.keys(cases).forEach(function (hash) {
|
||||||
|
it('should be equal', function (done) {
|
||||||
|
var worker = new Worker(WORKER);
|
||||||
|
worker.onmessage = function(event) {
|
||||||
|
expect(event.data).to.be(hash);
|
||||||
|
if (worker.terminate) {
|
||||||
|
worker.terminate();
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
worker.postMessage(SOURCE);
|
||||||
|
worker.postMessage(cases[hash]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})(Worker, WORKER, SOURCE);
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>MD5</title>
|
||||||
|
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
|
||||||
|
<script src="../node_modules/mocha/mocha.js"></script>
|
||||||
|
<script src="../node_modules/expect.js/index.js"></script>
|
||||||
|
<script src="../src/md5.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="mocha"></div>
|
||||||
|
<script>
|
||||||
|
WORKER = 'worker.js';
|
||||||
|
SOURCE = '../src/md5.js';
|
||||||
|
mocha.setup('bdd');
|
||||||
|
</script>
|
||||||
|
<script src="worker-test.js"></script>
|
||||||
|
<script>
|
||||||
|
mocha.run();
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
var imported = false;
|
||||||
|
onmessage = function(e) {
|
||||||
|
if (imported) {
|
||||||
|
postMessage(md5(e.data));
|
||||||
|
if (typeof exports !== 'undefined') {
|
||||||
|
imported = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
imported = true;
|
||||||
|
importScripts(e.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user