|
1 | 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) |
2 | 5 |
|
3 | | -Streamable SHA hashes in pure javascript. |
| 6 | +[](https://github.com/feross/standard) |
4 | 7 |
|
5 | | -[](http://travis-ci.org/crypto-browserify/sha.js) |
6 | | -[](https://www.npmjs.org/package/sha.js) |
| 8 | +Node style `SHA` on pure JavaScript. |
7 | 9 |
|
| 10 | +```js |
| 11 | +var shajs = require('sha.js') |
8 | 12 |
|
9 | | -## Example |
10 | | - |
11 | | -``` js |
12 | | -var createHash = require('sha.js') |
13 | | - |
14 | | -var sha256 = createHash('sha256') |
15 | | -var sha512 = createHash('sha512') |
16 | | - |
17 | | -var h = sha256.update('abc', 'utf8').digest('hex') |
18 | | -console.log(h) //ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad |
19 | | - |
20 | | -//LEGACY, do not use in new systems: |
21 | | -var sha0 = createHash('sha') |
22 | | -var sha1 = createHash('sha1') |
23 | | - |
| 13 | +console.log(shajs('sha256').update('42').digest('hex')) |
| 14 | +// => 73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049 |
| 15 | +console.log(new shajs.SHA256().update('42').digest('hex')) |
| 16 | +// => 73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049 |
24 | 17 |
|
| 18 | +var sha256stream = shajs('sha256') |
| 19 | +sha256stream.end('42') |
| 20 | +console.log(sha256stream.read().toString('hex')) |
| 21 | +// => 73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049 |
25 | 22 | ``` |
26 | 23 |
|
27 | 24 | ## supported hashes |
| 25 | +`sha.js` currently implements: |
28 | 26 |
|
29 | | -sha.js currently implements: |
| 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 |
30 | 33 |
|
31 | 34 |
|
32 | | -* sha256 |
33 | | -* sha512 |
34 | | -* sha1 (legacy, no not use in new systems) |
35 | | -* sha (legacy, no not use in new systems) |
36 | | - |
37 | | -## Note |
38 | | - |
| 35 | +## Not an actual stream |
39 | 36 | Note, this doesn't actually implement a stream, but wrapping this in a stream is trivial. |
40 | | -but is does update incrementally, so you can hash things larger than ram, and also, since it reuses |
41 | | -the typedarrays, it uses a constant amount of memory (except when using base64 or utf8 encoding, |
42 | | -see code comments) |
| 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). |
43 | 38 |
|
44 | 39 |
|
45 | 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). |
46 | 42 |
|
47 | | -This work is derived from Paul Johnston's ["A JavaScript implementation of the Secure Hash Algorithm"] |
48 | | -(http://pajhome.org.uk/crypt/md5/sha1.html) |
49 | | - |
50 | | - |
51 | | - |
52 | | -## License |
53 | 43 |
|
54 | | -MIT |
| 44 | +## LICENSE [MIT](LICENSE) |
0 commit comments