sha512
JavaScript component to compute the SHA512 of bytes or string. Can also compute HMAC as well.
Information
Install
npm install --save sha512
Usage
sha512(input)
Input either a string or Buffer
. Output is a Buffer
.
var sha512 = require('sha512')
var hash = sha512("hello")
console.log(hash.toString('hex'))
// => 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043
hmac(key)
Returns hmac
object with methods reset()
, update(message)
, finalize([message])
.
finalize([message])
returns Buffer
.
var sha512 = require('sha512')
var key = "super secret"
var hasher = sha512.hmac(key)
//can also call 'update(message)' and then 'finalize()'
var hash = hasher.finalize('hello man')
console.log(hash.toString('hex'))
// => 292f154b455f464131e8af89478e0a2af37fecf5de2e9cf998df1d9447f5856d146a1660708564bb7fd76d2fe80ab92a31af70e1d69a34f6b5b4839bdb26cbab
Credits
Most of the code from CryptoJS https://code.google.com/p/crypto-js/