hashifier
v1.0.0
Published
crypto module wrapper for password hashing using pbkdf2
Downloads
4
Maintainers
Readme
Hashifier
Light-weight wrapper to nodejs crypto library for hashing passwords using pbkdf2
Requirements
node 6.
Install
npm install hashifier
API
Each function returns a promise that resolves as specified.
Any errors encountered by nodejs (i.e. passing 0 for iterations) will reject the promise.
hash(plainText, options?)
- hash a given password
- resolves to an object, {hash, salt}
- see options below
compare(plainText, hash, salt, options?)
- compare a previously hashed password
- resolves to a boolean
- see options below
options
- iterations - number of iterations to hash (default 100,000)
- algorithm - algorithm to use for hashing (default sha512)
- encoding - output encoding to use (default hex)
- saltLength - number of bytes to use for the salt (default 128)
- keyLength - length of the key (default 128)
Usage
const hashifier = require('hashifier')
// options are optional, following is default
const options = {
iterations: 100000
algorithm: 'sha512'
encoding: 'hex'
saltLength: = 128
keyLength: 128
}
hashifier.hash('my password', options) // {salt: string, hash: string}
.then(result => {
hashifier.compare('my password', result.hash, result.salt, options).then(result => assert.ok(result)) // true
hashifier.compare('not my password', result.hash, result.salt, options).then(result => result.notOk(result)) // false
})
License
MIT.