Crypto
Node.js crypto module — cryptographic primitives and utilities. Also exposes the Web Crypto API via crypto.webcrypto.
Beyond this IDL surface, the enriched module also provides: createCipheriv, createDecipheriv, createSign, createVerify, generateKeyPairSync, generateKeyPair, createSecretKey, createPublicKey, createPrivateKey, createDiffieHellman, getDiffieHellman, createECDH, getCurves, publicEncrypt, privateDecrypt, publicDecrypt, privateEncrypt, sign, verify, hash, hkdfSync, hkdf, argon2Sync, argon2, encapsulate, decapsulate, getCipherInfo, getFips, setFips, checkPrime, checkPrimeSync, generatePrime, generatePrimeSync, pseudoRandomBytes, getRandomValues, secureHeapUsed, Certificate, DiffieHellman, DiffieHellmanGroup, ECDH, Sign, Verify, Cipheriv, Decipheriv, Hash, Hmac constructors, subtle, and webcrypto.
Module:node:crypto
Support: Experimental
Since: 1.1.0
Docs: Node.js Docs
16 members: 16 undocumented
Static Methods
Properties
---
Details
createHash(algorithm, options)
static createHash(algorithm: string, options?: object): Hash
static createHash(algorithm: string, options?: object): Hash
Creates and returns a Hash object for the given algorithm.| Parameter | Type | Description |
|---|---|---|
algorithm | string | Hash algorithm name (e.g. "sha256", "sha512") |
options (optional) | object |
Error--- If the algorithm is not supported
createHmac(algorithm, key)
static createHmac(algorithm: string, key: (string or BufferSource)): Hmac
static createHmac(algorithm: string, key: (string or BufferSource)): Hmac
Creates and returns an Hmac object for the given algorithm and key.| Parameter | Type | Description |
|---|---|---|
algorithm | string | HMAC algorithm name (e.g. "sha256") |
key | (string or BufferSource) | Secret key as string or buffer |
Error--- If the algorithm is not supported
randomBytes(size)
static randomBytes(size: u32): Buffer
static randomBytes(size: u32): Buffer
Generates cryptographically strong pseudorandom bytes.| Parameter | Type | Description |
|---|---|---|
size | u32 | Number of bytes to generate |
Error--- If the entropy source is unavailable
timingSafeEqual(a, b)
static timingSafeEqual(a: BufferSource, b: BufferSource): boolean
static timingSafeEqual(a: BufferSource, b: BufferSource): boolean
Compares two buffers in constant time to prevent timing attacks.| Parameter | Type | Description |
|---|---|---|
a | BufferSource | First buffer |
b | BufferSource | Second buffer |
Error--- If the buffers are not the same length
Interface Hash
Incremental cryptographic hash computation object. Created via crypto.createHash(); not constructable directly.
Since: 1.1.0 Docs: Node.js Docs3 members: 3 undocumented
Methods
---
Interface Hmac
Incremental HMAC computation object. Created via crypto.createHmac(); not constructable directly.
Since: 1.1.0 Docs: Node.js Docs2 members: 2 undocumented
Methods
---