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
| Name | Type | Description |
|---|---|---|
| password | string | Buffer | Password bytes. |
| salt | string | Buffer | Unique random salt. |
| keylen | number | Derived byte count. |
| options | object | Cost configuration. |
| callback | Function | Error-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));