dcryptjs v1.0.5
dcrypt.js
The library is compatible with CommonJS and AMD loaders and is exposed globally as dcodeIO.dcrypt if neither is available.
node.js
On node.js, the inbuilt crypto module's randomBytes interface is used to obtain secure random numbers.
npm install dcryptjs
var dcrypt = require('dcryptjs');
...
Browser
In the browser, dcrypt.js relies on Web Crypto API's getRandomValues interface to obtain secure random numbers. If no cryptographically secure source of randomness is available, you may specify one through dcrypt.setRandomFallback.
Usage
To hash a password:
var dcrypt = require('dcryptjs');
var hashPassword = dcrypt.hash("Abc@123");
// Store hashPassword in your password DB.
To check a password:
// Load hashPassword from your password DB.
dcrypt.compare("Abc@123", hashPassword); // true
dcrypt.compare("not_bacon", hashPassword); // false
Note: Under the hood, asynchronisation splits a crypto operation into small chunks. After the completion of a chunk, the execution of the next chunk is placed on the back of JS event loop queue, thus efficiently sharing the computational resources with the other operations in the queue.