Crypto

crypto.scrypt()

Derives key bytes using a memory-costed password KDF. Use a fresh random salt per credential and review work factors against deployment resources. This is a primitive demonstration, not a complete password storage format. Tested on Node.js 22.16.0. Example output (one line per entry): ["32 true false"].

Formal Syntax & Structure

nodejs syntaxnodejs
crypto.scrypt(password, salt, keylen[, options], callback)

Parameters & Attributes

NameTypeDescription
passwordstring | BufferPassword bytes.
saltstring | BufferUnique random salt.
keylennumberDerived byte count.
optionsobjectCost configuration.
callbackFunctionError-first completion callback.

Return Value

undefined

Derived bytes delivered to callback.

Working Example

Example Snippetnodejs
import { scrypt, randomBytes, timingSafeEqual } from 'node:crypto';import { promisify } from 'node:util';const derive = promisify(scrypt), salt = randomBytes(16);const a = await derive('demo only', salt, 32), b = await derive('demo only', salt, 32), c = await derive('different', salt, 32);console.log(a.length, timingSafeEqual(a, b), timingSafeEqual(a, c));
Node.js Reference