Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@bleskomat/scrypt
Advanced tools
Node.js module that provides a wrapper API to node's built-in scrypt implementation.
Node.js module that provides a wrapper API to node's built-in scrypt implementation.
Why not just use the built-in scrypt of Node.js? You could, but it's nice to have a portable serialization format that can be stored in a database or configuration file long-term without worrying about incompatibility when changing hashing options. An example of the serialization format used by this module:
$scrypt$1$14$iAoNah2WdPs7s2JZTd0Velb6ycQ=$ttq2cz7NoXNkAs6Nbl+TNKZsYFaEQJFcIWNTApiV67k=
$scrypt$
is the prefix and the $
symbol is used as a delimiter. The first value is the serialization format version - in this case 1
. The second value is the cost exponent - in this case 14
meaning the cost is equal to 2^14 or 16384. The third value is the base64-encoded salt. And the fourth value is the base64-encoded derived key.
Add to your application via npm
:
npm install @bleskomat/scrypt
Create a hash of a secret:
const scrypt = require('@bleskomat/scrypt');
const secret = 'super secret password';
const salt = scrypt.generateSalt();
scrypt.hash(secret, salt).then(result => {
console.log(result);
// $scrypt$1$14$iAoNah2WdPs7s2JZTd0Velb6ycQ=$ttq2cz7NoXNkAs6Nbl+TNKZsYFaEQJFcIWNTApiV67k=
});
The complete function signature is scrypt.hash(secret, salt, keylen, options)
. The keylen
and options
arguments are passed to crypto.scrypt. The default value for keylen
is 32 bytes.
And scrypt.generateSalt(numBytes)
where numBytes
are the number of random bytes to generate. The default value for numBytes
is 20.
Check if a secret matches a hash:
const scrypt = require('@bleskomat/scrypt');
const secret = 'super secret password';
const hash = '$scrypt$1$14$iAoNah2WdPs7s2JZTd0Velb6ycQ=$ttq2cz7NoXNkAs6Nbl+TNKZsYFaEQJFcIWNTApiV67k=';
scrypt.compare(secret, hash).then(result => {
console.log(result ? 'OK' : 'DOES NOT MATCH');
});
Synchronously create a hash:
const scrypt = require('@bleskomat/scrypt');
const secret = 'super secret password';
const salt = scrypt.generateSalt();
const result = scrypt.hashSync(secret, salt);
console.log(result);
// $scrypt$1$14$iAoNah2WdPs7s2JZTd0Velb6ycQ=$ttq2cz7NoXNkAs6Nbl+TNKZsYFaEQJFcIWNTApiV67k=
The complete function signature is scrypt.hashSync(secret, salt, keylen, options)
. The keylen
and options
arguments are passed to crypto.scryptSync. The default value for keylen
is 32 bytes.
And scrypt.generateSalt(numBytes)
where numBytes
are the number of random bytes to generate. The default value for numBytes
is 20.
Synchronously check if a secret matches a hash:
const scrypt = require('@bleskomat/scrypt');
const secret = 'super secret password';
const hash = '$scrypt$1$14$iAoNah2WdPs7s2JZTd0Velb6ycQ=$ttq2cz7NoXNkAs6Nbl+TNKZsYFaEQJFcIWNTApiV67k=';
const result = scrypt.compareSync(secret, hash);
console.log(result ? 'OK' : 'DOES NOT MATCH');
Run automated tests as follows:
npm test
See CHANGELOG.md
This software is MIT licensed:
A short, permissive software license. Basically, you can do whatever you want as long as you include the original copyright and license notice in any copy of the software/source. There are many variations of this license in use.
FAQs
Node.js module that provides a wrapper API to node's built-in scrypt implementation.
We found that @bleskomat/scrypt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.