You should probably use easy-pbkdf2 instead as it uses node's built-in crypto.pbkdf2
method.
crypto-PBKDF2
crypto.js' PBKDF2 standalone implementation for npm.
Usage (based on Stack Exchange's PBKDF2 implementation):
var CryptoJS = require("crypto-PBKDF2");
var DEFAULT_HASH_ITERATIONS = 4000;
var SALT_SIZE = 192/8;
var KEY_SIZE = 768/32;
function generateSalt(explicitIterations){
var defaultHashIterations = DEFAULT_HASH_ITERATIONS;
if(explicitIterations !== null && explicitIterations !== undefined){
if( parseInt(explicitIterations, 10) === explicitIterations ){
throw new Error("explicitIterations must be an integer");
}
if( explicitIterations < DEFAULT_HASH_ITERATIONS){
throw new Error("explicitIterations cannot be less than " + DEFAULT_HASH_ITERATIONS);
}
}
var bytes = CryptoJS.lib.WordArray.random(SALT_SIZE);
var iterations = (explicitIterations || defaultHashIterations).toString(16);
return iterations + "." + bytes.toString(CryptoJS.enc.Base64);
}
function hashPassword( value, salt ){
var i = salt.indexOf(".");
var iters = parseInt(salt.substring(0, i), 16);
var key = CryptoJS.PBKDF2(value, salt, { "keySize": KEY_SIZE, "iterations": iters });
return key.toString(CryptoJS.enc.Base64);
}
function checkPassword(candidate, salt, hashed){
return hashPassword( candidate, salt ) === hashed;
}
var salt = generateSalt();
var hashedPassword = hashPassword( "password", salt );
var isPassword = checkPassword( "password", salt, hashedPassword );