![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
crypto-pbkdf2
Advanced tools
CryptoJS' PBKDF2 rollup as a stand-alone npm package. Managed by David Murdoch
crypto.pbkdf2
method.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;
/**
* Convenience wrapper around CryptoJS.lib.WordArray.random to grab a new salt value.
* Treat this value as opaque, as it captures iterations.
*
* @param {number} explicitIterations An integer
* @return {string} Return iterations and salt together as one string ({hex-iterations}.{base64-salt})
*/
function generateSalt(explicitIterations){
var defaultHashIterations = DEFAULT_HASH_ITERATIONS;
if(explicitIterations !== null && explicitIterations !== undefined){
// make sure explicitIterations is an integer
if( parseInt(explicitIterations, 10) === explicitIterations ){
throw new Error("explicitIterations must be an integer");
}
// and that it is smaller than our default hash iterations
if( explicitIterations < DEFAULT_HASH_ITERATIONS){
throw new Error("explicitIterations cannot be less than " + DEFAULT_HASH_ITERATIONS);
}
}
// get some random bytes
var bytes = CryptoJS.lib.WordArray.random(SALT_SIZE);
// convert iterations to Hexadecimal
var iterations = (explicitIterations || defaultHashIterations).toString(16);
// concat the iterations and random bytes together.
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;
}
/* Save BOTH the salt and the hashedPassword to your database so you can validate the password later */
var salt = generateSalt();
var hashedPassword = hashPassword( "password", salt );
var isPassword = checkPassword( "password", salt, hashedPassword ); // true
FAQs
CryptoJS' PBKDF2 rollup as a stand-alone npm package. Managed by David Murdoch
The npm package crypto-pbkdf2 receives a total of 9 weekly downloads. As such, crypto-pbkdf2 popularity was classified as not popular.
We found that crypto-pbkdf2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.