2017-05-03 15:35:00 +02:00
# sha.js
2017-12-10 21:51:33 +01:00
[](https://www.npmjs.org/package/sha.js)
[](https://travis-ci.org/crypto-browserify/sha.js)
[](https://david-dm.org/crypto-browserify/sha.js#info=dependencies)
2017-05-03 15:35:00 +02:00
2017-12-10 21:51:33 +01:00
[](https://github.com/feross/standard)
2017-05-03 15:35:00 +02:00
2017-12-10 21:51:33 +01:00
Node style `SHA` on pure JavaScript.
2017-05-03 15:35:00 +02:00
2017-12-10 21:51:33 +01:00
```js
var shajs = require('sha.js')
2017-05-03 15:35:00 +02:00
2017-12-10 21:51:33 +01:00
console.log(shajs('sha256').update('42').digest('hex'))
// => 73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049
console.log(new shajs.sha256().update('42').digest('hex'))
// => 73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049
2017-05-03 15:35:00 +02:00
2017-12-10 21:51:33 +01:00
var sha256stream = shajs('sha256')
sha256stream.end('42')
console.log(sha256stream.read().toString('hex'))
// => 73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049
2017-05-03 15:35:00 +02:00
```
## supported hashes
2017-12-10 21:51:33 +01:00
`sha.js` currently implements:
2017-05-03 15:35:00 +02:00
2017-12-10 21:51:33 +01:00
- SHA (SHA-0) -- **legacy, do not use in new systems**
- SHA-1 -- **legacy, do not use in new systems**
- SHA-224
- SHA-256
- SHA-384
- SHA-512
2017-05-03 15:35:00 +02:00
2017-12-10 21:51:33 +01:00
## Not an actual stream
2017-05-03 15:35:00 +02:00
Note, this doesn't actually implement a stream, but wrapping this in a stream is trivial.
2017-12-10 21:51:33 +01:00
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).
2017-05-03 15:35:00 +02:00
## Acknowledgements
2017-12-10 21:51:33 +01:00
This work is derived from Paul Johnston's [A JavaScript implementation of the Secure Hash Algorithm ](http://pajhome.org.uk/crypt/md5/sha1.html ).
2017-05-03 15:35:00 +02:00
2017-12-10 21:51:33 +01:00
## LICENSE [MIT](LICENSE)