1 | # sha.js
|
---|
2 | [](https://www.npmjs.org/package/sha.js)
|
---|
3 | [](https://travis-ci.org/crypto-browserify/sha.js)
|
---|
4 | [](https://david-dm.org/crypto-browserify/sha.js#info=dependencies)
|
---|
5 |
|
---|
6 | [](https://github.com/feross/standard)
|
---|
7 |
|
---|
8 | Node style `SHA` on pure JavaScript.
|
---|
9 |
|
---|
10 | ```js
|
---|
11 | var shajs = require('sha.js')
|
---|
12 |
|
---|
13 | console.log(shajs('sha256').update('42').digest('hex'))
|
---|
14 | // => 73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049
|
---|
15 | console.log(new shajs.sha256().update('42').digest('hex'))
|
---|
16 | // => 73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049
|
---|
17 |
|
---|
18 | var sha256stream = shajs('sha256')
|
---|
19 | sha256stream.end('42')
|
---|
20 | console.log(sha256stream.read().toString('hex'))
|
---|
21 | // => 73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049
|
---|
22 | ```
|
---|
23 |
|
---|
24 | ## supported hashes
|
---|
25 | `sha.js` currently implements:
|
---|
26 |
|
---|
27 | - SHA (SHA-0) -- **legacy, do not use in new systems**
|
---|
28 | - SHA-1 -- **legacy, do not use in new systems**
|
---|
29 | - SHA-224
|
---|
30 | - SHA-256
|
---|
31 | - SHA-384
|
---|
32 | - SHA-512
|
---|
33 |
|
---|
34 |
|
---|
35 | ## Not an actual stream
|
---|
36 | Note, this doesn't actually implement a stream, but wrapping this in a stream is trivial.
|
---|
37 | It does update incrementally, so you can hash things larger than RAM, as it uses a constant amount of memory (except when using base64 or utf8 encoding, see code comments).
|
---|
38 |
|
---|
39 |
|
---|
40 | ## Acknowledgements
|
---|
41 | This work is derived from Paul Johnston's [A JavaScript implementation of the Secure Hash Algorithm](http://pajhome.org.uk/crypt/md5/sha1.html).
|
---|
42 |
|
---|
43 |
|
---|
44 | ## LICENSE [MIT](LICENSE)
|
---|