Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
crypto-pbkdf2
Advanced tools
CryptoJS' PBKDF2 rollup as a stand-alone npm package. Managed by David Murdoch
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 15 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.