sechash

Secure password hashing with salt and key stretching

Author: James Brumond

Version: 0.2.0

Copyright 2012 James Brumond

Dual licensed under MIT and GPL

Install

$ npm install sechash

Usage

Running a simple hash

var sechash =require('sechash');
// This will do a simple sha1 hash, the same as if you used the// built-in "crypto" module.var hash = sechash.basicHash('sha1', 'Your String');
// You can also use the testBasicHash method to easily test if// a string matches a hash
sechash.testBasicHash('sha1', 'Your String', hash); // true

More Advanced Configuration

The following options can be given in the options object seen above. Also, the options object can also be excluded and all default options will be used.

algorithm

The hashing algorithm to use. Common hashing algorithms include "sha1", "md5", "sha256", and "sha512". The default used by sechash is "sha1".

iterations

One method used by sechash to make hashes more secure is key stretching, or iterating over a hash multiple times with the expressed purpose of slowing down the hashing process. This value is the number of times to hash the given string. The default used is 2000.

salt

Another method used by sechash is called salt. By default, sechash will randomly generate some salt to use, but you can provide this value to specify the salt string.

intervalLength

This value only applies to the asynchronous functions. Key stretching greatly increases the amount of time to run a hash, which means that (especially for large iterations values) your application will be blocked for a short while. To avoid blocking for too long, these functions will yield control back to the event loop every so often to allow other parts of the application to run. This value refers to how many iterations should run between "yields". This value defaults to 500.

includeMeta

When you generate a hash using sechash, the actual hash will often be prefixed with some meta data about how the hash was generated.

This allows sechash to correctly repeat the hashing process, therefore making hash testing possible. If you do not want this meta data included in the hash, you can set includeMeta to false. One reason for doing this may be that, instead of using a random salt, you may want to use one secret salt value and you don't want this value stored with the hash.