* Added support for update hash.

* Added support for bytes array output.
* Added support for ArrayBuffer output.
* Added support for AMD.
This commit is contained in:
Yi-Cyuan
2015-12-28 15:54:38 +08:00
parent 201bff606f
commit 261e55bd5c
43 changed files with 16037 additions and 413 deletions
+28 -57
View File
@@ -25,79 +25,50 @@ For node.js, you can use this command to install:
You could use like this:
```JavaScript
md5('Message to hash');
var hash = md5.create();
hash.update('Message to hash');
hash.hex();
```
If you use node.js, you should require the module first:
```JavaScript
md5 = require('js-md5');
```
It supports AMD:
```JavaScript
require(['your/path/md5.js'], function(md5) {
// ...
});
```
[See document](https://emn178.github.com/js-md5/doc/)
## Example
Code
```JavaScript
md5('');
md5('The quick brown fox jumps over the lazy dog');
md5('The quick brown fox jumps over the lazy dog.');
md5(''); // d41d8cd98f00b204e9800998ecf8427e
md5('The quick brown fox jumps over the lazy dog'); // 9e107d9d372bb6826bd81d3542a419d6
md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0
// It also supports UTF-8 encoding
md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07
// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer`
md5([]); // d41d8cd98f00b204e9800998ecf8427e
md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e
// Different output
md5(''); // d41d8cd98f00b204e9800998ecf8427e
md5.hex(''); // d41d8cd98f00b204e9800998ecf8427e
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.buffer(''); // ArrayBuffer
```
Output
d41d8cd98f00b204e9800998ecf8427e
9e107d9d372bb6826bd81d3542a419d6
e4d909c290d0fb1ca068ffaddf22cbd0
It also supports UTF-8 encoding:
Code
```JavaScript
md5('中文');
```
Output
a7bac2239fcdcb3a067903d8077c4a07
It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` input:
Code
```JavaScript
md5([]);
md5(new Uint8Array([]));
```
Output
d41d8cd98f00b204e9800998ecf8427e
d41d8cd98f00b204e9800998ecf8427e
## Benchmark
[UTF8](http://jsperf.com/md5-shootout/81)
[ASCII](http://jsperf.com/md5-shootout/82)
## Extensions
### jQuery
If you prefer jQuery style, you can add following code to add a jQuery extension.
Code
```JavaScript
jQuery.md5 = md5
```
And then you could use like this:
```JavaScript
$.md5('message');
```
### Prototype
If you prefer prototype style, you can add following code to add a prototype extension.
Code
```JavaScript
String.prototype.md5 = function() {
return md5(this);
};
```
And then you could use like this:
```JavaScript
'message'.md5();
```
## License
The project is released under the [MIT license](http://www.opensource.org/licenses/MIT).
## Contact
The project's website is located at https://github.com/emn178/js-md5
Author: emn178@gmail.com
Author: Yi-Cyuan Chen (emn178@gmail.com)