node:crypto
Node-compatible cryptographic hashes, HMACs, CSPRNG, PBKDF2, and constant-time comparison.
Available in both vjs and vjs-lite runtimes. Enabled by default unless
--no-node-compat is passed.
Supported digest algorithms are "sha256", "sha384", and "sha512"
(case-insensitive). Legacy algorithms such as MD5 and SHA-1 are intentionally
rejected with ERR_CRYPTO_HASH_UNKNOWN / ERR_CRYPTO_INVALID_DIGEST.
import ... from "node:crypto"
node-compat (enabled by default; disable with --no-node-compat)scrypt, hkdf, pbkdf2, and randomFill are V8-only (vjs). Synchronous exports and webcrypto run on both vjs and vjs-lite.Example
Section titled “Example”import { createHash, createHmac, randomBytes, timingSafeEqual } from "node:crypto";
const digest = createHash("sha256").update("hello").digest("hex");const mac = createHmac("sha256", "secret").update("hello").digest();const token = randomBytes(16);console.log(digest, mac.byteLength, token.byteLength);console.log(timingSafeEqual(mac, mac));randomBytesv0.0.0-alpha.0size cryptographically strong pseudo-random bytes.randomUUIDv0.0.0-alpha.0createHashv0.0.0-alpha.0Hash instance for algorithm.createHmacv0.0.0-alpha.0Hmac instance for algorithm and key.pbkdf2Syncv0.0.0-alpha.0timingSafeEqualv0.0.0-alpha.0createCipherivv0.0.0-alpha.2Cipher object using algorithm, key, and iv.createDecipherivv0.0.0-alpha.2Decipher object using algorithm, key, and iv.scryptSyncv0.0.0-alpha.2scrypt.scryptvjs onlyv0.0.0-alpha.2scrypt and invoke callback.hkdfSyncv0.0.0-alpha.2hkdfvjs onlyv0.0.0-alpha.2callback.pbkdf2vjs onlyv0.0.0-alpha.2callback.hashv0.0.0-alpha.2"hex").randomIntv0.0.0-alpha.2n in 0 <= n < max.randomFillSyncv0.0.0-alpha.2buffer (or sub-range [offset, offset + size)) with random bytes.randomFillvjs onlyv0.0.0-alpha.2buffer with cryptographically strong random bytes.getHashesv0.0.0-alpha.2Hashv0.0.0-alpha.0createHash.Hmacv0.0.0-alpha.0createHmac.CipherOptionsv0.0.0-alpha.2createCipheriv and createDecipheriv.Cipherv0.0.0-alpha.2createCipheriv.Decipherv0.0.0-alpha.2createDecipheriv.ScryptOptionsv0.0.0-alpha.2scrypt() and scryptSync().WebCryptoKeyv0.0.0-alpha.2webcrypto.subtle.WebCryptoKeyPairv0.0.0-alpha.2webcrypto.subtle.generateKey for asymmetric algorithms.WebSubtleCryptov0.0.0-alpha.2SubtleCrypto interface exposed on webcrypto.subtle.WebCryptov0.0.0-alpha.2crypto.webcrypto.Functions
Section titled “Functions”randomBytes
Section titled “randomBytes”export function randomBytes(size: number): Uint8Array;
Generate size cryptographically strong pseudo-random bytes.
Backed by the operating system CSPRNG and bounded to 8 MiB per call.
| Name | Type | Description |
|---|---|---|
size | number | Number of random bytes to generate (0 to 8_388_608). |
RangeError— whensizeis negative, not an integer, or exceeds 8 MiB (VAEL_CRYPTO_LIMIT).Error— if the operating system CSPRNG fails.
import { Buffer } from "node:buffer";import { randomBytes } from "node:crypto";
const nonce = randomBytes(12);console.log(Buffer.from(nonce).toString("hex"));randomUUID
Section titled “randomUUID”export function randomUUID(): string;
Generate a random RFC 4122/9562 version 4 UUID string.
string — Lowercase hyphenated UUID v4 string (36 characters).Error— withcode = "ERR_UNAVAILABLE"if the operating system CSPRNG fails.
import { randomUUID } from "node:crypto";
const id = randomUUID();console.log(id);createHash
Section titled “createHash”export function createHash(algorithm: string): Hash;
Create an incremental Hash instance for algorithm.
Supports "sha256", "sha384", and "sha512" (case-insensitive). Up to
1024 digest handles may be open simultaneously.
| Name | Type | Description |
|---|---|---|
algorithm | string | Hash algorithm name ("sha256", "sha384", or "sha512"). |
Hash — Incremental Hash instance.TypeError— whenalgorithmis not a string.Error— withcode = "ERR_CRYPTO_HASH_UNKNOWN"whenalgorithmis unsupported.RangeError— withcode = "ERR_CRYPTO_TOO_MANY_OBJECTS"if more than 1024 digest handles are open.
import { createHash } from "node:crypto";
const hex = createHash("sha256").update("vaeljs", "utf8").digest("hex");console.log(hex);createHmac
Section titled “createHmac”export function createHmac(algorithm: string, key: BinaryLike): Hmac;
Create an incremental Hmac instance for algorithm and key.
Supports "sha256", "sha384", and "sha512" (case-insensitive), with
keys up to 1 MiB. Up to 1024 digest handles may be open simultaneously.
| Name | Type | Description |
|---|---|---|
algorithm | string | Hash algorithm name ("sha256", "sha384", or "sha512"). |
key | BinaryLike | Secret HMAC key (UTF-8 string or byte view, max 1 MiB). |
Hmac — Incremental Hmac instance.TypeError— whenalgorithmis not a string orkeyhas an invalid type.Error— withcode = "ERR_CRYPTO_HASH_UNKNOWN"whenalgorithmis unsupported.RangeError— withcode = "VAEL_CRYPTO_LIMIT"ifkeyexceeds 1 MiB, or"ERR_CRYPTO_TOO_MANY_OBJECTS"if too many handles are open.
import { createHmac } from "node:crypto";
const tag = createHmac("sha256", "signing-key").update("payload").digest("base64url");console.log(tag);pbkdf2Sync
Section titled “pbkdf2Sync”export function pbkdf2Sync(
password: BinaryLike,
salt: BinaryLike,
iterations: number,
keylen: number,
digest: string,
): Uint8Array;
Synchronously derive a key using PBKDF2-HMAC.
Supports "sha256", "sha384", and "sha512" digests. Bounded to
1..=1_000_000 iterations, keylen <= 1024, and 1 MiB max password/salt.
| Name | Type | Description |
|---|---|---|
password | BinaryLike | Input password bytes or UTF-8 string (max 1 MiB). |
salt | BinaryLike | Cryptographic salt bytes or UTF-8 string (max 1 MiB). |
iterations | number | Iteration count (1 to 1_000_000). |
keylen | number | Derived key length in bytes (0 to 1024). |
digest | string | Hash algorithm name ("sha256", "sha384", or "sha512"). |
TypeError— withcode = "ERR_CRYPTO_INVALID_DIGEST"whendigestis unsupported, or on invalid argument types.RangeError— wheniterations,keylen,password, orsaltis out of bounds.
import { Buffer } from "node:buffer";import { pbkdf2Sync } from "node:crypto";
const key = pbkdf2Sync("passphrase", "salt-value", 10000, 32, "sha256");console.log(Buffer.from(key).toString("hex"));timingSafeEqual
Section titled “timingSafeEqual”export function timingSafeEqual(a: ArrayBufferView, b: ArrayBufferView): boolean;
Constant-time equality comparison for equal-length byte buffers.
| Name | Type | Description |
|---|---|---|
a | ArrayBufferView | First TypedArray or DataView to compare. |
b | ArrayBufferView | Second TypedArray or DataView to compare (must have the same byteLength as a). |
boolean — true if a and b contain identical bytes, otherwise false.TypeError— whenaorbis not anArrayBufferView.RangeError— withcode = "ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH"whena.byteLength !== b.byteLength.
import { Buffer } from "node:buffer";import { timingSafeEqual } from "node:crypto";
const left = Buffer.from("secret", "utf8");const right = Buffer.from("secret", "utf8");console.log(timingSafeEqual(left, right)); // truecreateCipheriv
Section titled “createCipheriv”export function createCipheriv(
algorithm: string,
key: BinaryLike,
iv: BinaryLike | null,
options?: CipherOptions,
): Cipher;
Create a symmetric Cipher object using algorithm, key, and iv.
| Name | Type | Description |
|---|---|---|
algorithm | string | Cipher algorithm name (for example "aes-256-gcm" or "aes-256-cbc"). |
key | BinaryLike | Raw key bytes or UTF-8 string. |
iv | BinaryLike | null | Initialization vector (or null for ECB modes). |
options optional | CipherOptions | Optional cipher configuration (authTagLength). |
Cipher — Symmetric Cipher instance.createDecipheriv
Section titled “createDecipheriv”export function createDecipheriv(
algorithm: string,
key: BinaryLike,
iv: BinaryLike | null,
options?: CipherOptions,
): Decipher;
Create a symmetric Decipher object using algorithm, key, and iv.
| Name | Type | Description |
|---|---|---|
algorithm | string | Cipher algorithm name (for example "aes-256-gcm" or "aes-256-cbc"). |
key | BinaryLike | Raw key bytes or UTF-8 string. |
iv | BinaryLike | null | Initialization vector (or null for ECB modes). |
options optional | CipherOptions | Optional cipher configuration (authTagLength). |
Decipher — Symmetric Decipher instance.scryptSync
Section titled “scryptSync”export function scryptSync(
password: BinaryLike,
salt: BinaryLike,
keylen: number,
options?: ScryptOptions,
): Uint8Array;
Synchronously derive a key using scrypt.
| Name | Type | Description |
|---|---|---|
password | BinaryLike | Input password bytes or UTF-8 string. |
salt | BinaryLike | Salt bytes or UTF-8 string. |
keylen | number | Derived key length in bytes. |
options optional | ScryptOptions | Optional cost parameters (N, r, p, maxmem). |
scrypt
Section titled “scrypt”export function scrypt(
password: BinaryLike,
salt: BinaryLike,
keylen: number,
callback: (err: Error | null, derivedKey: Uint8Array) => void,
): void;
export function scrypt(
password: BinaryLike,
salt: BinaryLike,
keylen: number,
options: ScryptOptions,
callback: (err: Error | null, derivedKey: Uint8Array) => void,
): void;
Asynchronously derive a key using scrypt and invoke callback.
Available in vjs only (vjs-lite provides synchronous scryptSync only).
scrypt(password, salt, keylen, callback)| Name | Type | Description |
|---|---|---|
password | BinaryLike | Input password bytes or UTF-8 string. |
salt | BinaryLike | Salt bytes or UTF-8 string. |
keylen | number | Derived key length in bytes. |
callback | (err: Error | null, derivedKey: Uint8Array) => void | Callback receiving (err, derivedKey). |
voidscrypt(password, salt, keylen, options, callback)Asynchronously derive a key using scrypt with options and invoke callback. Available in vjs only (vjs-lite provides synchronous scryptSync only).
| Name | Type | Description |
|---|---|---|
password | BinaryLike | Input password bytes or UTF-8 string. |
salt | BinaryLike | Salt bytes or UTF-8 string. |
keylen | number | Derived key length in bytes. |
options | ScryptOptions | Cost parameters (N, r, p, maxmem). |
callback | (err: Error | null, derivedKey: Uint8Array) => void | Callback receiving (err, derivedKey). |
voidhkdfSync
Section titled “hkdfSync”export function hkdfSync(
digest: string,
ikm: BinaryLike,
salt: BinaryLike,
info: BinaryLike,
keylen: number,
): ArrayBuffer;
Synchronously derive a key using HKDF (RFC 5869).
| Name | Type | Description |
|---|---|---|
digest | string | Hash algorithm name ("sha256", "sha384", or "sha512"). |
ikm | BinaryLike | Input keying material. |
salt | BinaryLike | Salt bytes or UTF-8 string. |
info | BinaryLike | Context/application-specific info bytes or UTF-8 string. |
keylen | number | Derived key length in bytes. |
ArrayBuffer — ArrayBuffer containing the derived key.export function hkdf(
digest: string,
ikm: BinaryLike,
salt: BinaryLike,
info: BinaryLike,
keylen: number,
callback: (err: Error | null, derivedKey: ArrayBuffer) => void,
): void;
Asynchronously derive a key using HKDF (RFC 5869) and invoke callback.
Available in vjs only (vjs-lite provides synchronous hkdfSync only).
| Name | Type | Description |
|---|---|---|
digest | string | Hash algorithm name ("sha256", "sha384", or "sha512"). |
ikm | BinaryLike | Input keying material. |
salt | BinaryLike | Salt bytes or UTF-8 string. |
info | BinaryLike | Context/application-specific info bytes or UTF-8 string. |
keylen | number | Derived key length in bytes. |
callback | (err: Error | null, derivedKey: ArrayBuffer) => void | Callback receiving (err, derivedKey). |
voidpbkdf2
Section titled “pbkdf2”export function pbkdf2(
password: BinaryLike,
salt: BinaryLike,
iterations: number,
keylen: number,
digest: string,
callback: (err: Error | null, derivedKey: Uint8Array) => void,
): void;
Asynchronously derive a key using PBKDF2-HMAC and invoke callback.
Available in vjs only (vjs-lite provides synchronous pbkdf2Sync only).
| Name | Type | Description |
|---|---|---|
password | BinaryLike | Input password bytes or UTF-8 string. |
salt | BinaryLike | Cryptographic salt bytes or UTF-8 string. |
iterations | number | Iteration count. |
keylen | number | Derived key length in bytes. |
digest | string | Hash algorithm name ("sha256", "sha384", or "sha512"). |
callback | (err: Error | null, derivedKey: Uint8Array) => void | Callback receiving (err, derivedKey). |
voidexport function hash(
algorithm: string,
data: BinaryLike,
outputEncoding?: DigestEncoding,
): string;
export function hash(
algorithm: string,
data: BinaryLike,
outputEncoding: "buffer",
): Uint8Array;
One-shot cryptographic hash returning an encoded string (default "hex").
One-shot cryptographic hash returning raw digest bytes (outputEncoding: "buffer").
| Name | Type | Description |
|---|---|---|
algorithm | string | Hash algorithm name ("sha256", "sha384", or "sha512"). |
data | BinaryLike | Input bytes or UTF-8 string. |
outputEncoding optional | DigestEncoding | "buffer" | Output encoding (default "hex"); "buffer". |
string— Encoded digest string.Uint8Array— Raw digest bytes as aBuffer(Uint8Arraysubclass).
randomInt
Section titled “randomInt”export function randomInt(max: number): number;
export function randomInt(min: number, max: number): number;
Return a cryptographically random integer n in 0 <= n < max.
randomInt(max)| Name | Type | Description |
|---|---|---|
max | number | Exclusive upper bound. |
number — Uniformly distributed random integer.randomInt(min, max)Return a cryptographically random integer n in min <= n < max.
| Name | Type | Description |
|---|---|---|
min | number | Inclusive lower bound. |
max | number | Exclusive upper bound. |
number — Uniformly distributed random integer.randomFillSync
Section titled “randomFillSync”export function randomFillSync<T extends ArrayBufferView>(
buffer: T,
offset?: number,
size?: number,
): T;
Synchronously fill buffer (or sub-range [offset, offset + size)) with random bytes.
| Name | Type | Description |
|---|---|---|
buffer | T | Destination ArrayBufferView. |
offset optional | number | Element/byte offset to start filling (default 0). |
size optional | number | Number of elements/bytes to fill. |
T — The mutated buffer.randomFill
Section titled “randomFill”export function randomFill<T extends ArrayBufferView>(
buffer: T,
callback: (err: Error | null, buf: T) => void,
): void;
export function randomFill<T extends ArrayBufferView>(
buffer: T,
offset: number,
callback: (err: Error | null, buf: T) => void,
): void;
export function randomFill<T extends ArrayBufferView>(
buffer: T,
offset: number,
size: number,
callback: (err: Error | null, buf: T) => void,
): void;
Asynchronously fill buffer with cryptographically strong random bytes.
Available in vjs only (vjs-lite provides synchronous randomFillSync only).
randomFill(buffer, callback)| Name | Type | Description |
|---|---|---|
buffer | T | Destination ArrayBufferView. |
callback | (err: Error | null, buf: T) => void | Callback receiving (err, buf). |
voidrandomFill(buffer, offset, callback)Asynchronously fill buffer starting at offset with random bytes. Available in vjs only (vjs-lite provides synchronous randomFillSync only).
| Name | Type | Description |
|---|---|---|
buffer | T | Destination ArrayBufferView. |
offset | number | Byte/element offset. |
callback | (err: Error | null, buf: T) => void | Callback receiving (err, buf). |
voidrandomFill(buffer, offset, size, callback)Asynchronously fill size units of buffer starting at offset with random bytes. Available in vjs only (vjs-lite provides synchronous randomFillSync only).
| Name | Type | Description |
|---|---|---|
buffer | T | Destination ArrayBufferView. |
offset | number | Byte/element offset. |
size | number | Number of elements/bytes to fill. |
callback | (err: Error | null, buf: T) => void | Callback receiving (err, buf). |
voidgetHashes
Section titled “getHashes”export function getHashes(): string[];
Return an array of supported hash algorithm names.
string[] — Array of hash algorithm identifiers (such as ["sha256", "sha384", "sha512"]).Interfaces
Section titled “Interfaces”export interface Hash {
update(data: BinaryLike, inputEncoding?: string): this;
digest(): Uint8Array;
digest(encoding: DigestEncoding): string;
}
Incremental cryptographic hash object returned by createHash.
Hash.update
Section titled “Hash.update”update(data: BinaryLike, inputEncoding?: string): this;
Update hash content with data.
May be called repeatedly before digest() up to 16 MiB total input per
digest object. Fails after digest() has been called.
| Name | Type | Description |
|---|---|---|
data | BinaryLike | Input bytes or string to feed into the hash state. |
inputEncoding optional | string | Encoding used when data is a string (default "utf8"). |
this — this for method chaining.Error— ifdigest()was already called, or withcode = "VAEL_CRYPTO_LIMIT"if cumulative input exceeds 16 MiB.TypeError— whendatahas an invalid type orinputEncodingis unknown (ERR_UNKNOWN_ENCODING).
Hash.digest
Section titled “Hash.digest”digest(): Uint8Array;
digest(encoding: DigestEncoding): string;
Compute raw digest bytes.
Finalizes the hash state; subsequent update() or digest() calls throw.
Compute encoded digest string.
Finalizes the hash state; subsequent update() or digest() calls throw.
| Name | Type | Description |
|---|---|---|
encoding optional | DigestEncoding | Output string encoding ("hex", "base64", "base64url", "latin1", or "binary"). |
Uint8Array— Raw digest bytes as aBuffer(Uint8Arraysubclass).string— Encoded digest string.
Error— ifdigest()was already called.TypeError— withcode = "ERR_UNKNOWN_ENCODING"whenencodingis unsupported.
export interface Hmac {
update(data: BinaryLike, inputEncoding?: string): this;
digest(): Uint8Array;
digest(encoding: DigestEncoding): string;
}
Incremental cryptographic HMAC object returned by createHmac.
Hmac.update
Section titled “Hmac.update”update(data: BinaryLike, inputEncoding?: string): this;
Update HMAC content with data.
May be called repeatedly before digest() up to 16 MiB total input per
HMAC object. Fails after digest() has been called.
| Name | Type | Description |
|---|---|---|
data | BinaryLike | Input bytes or string to authenticate. |
inputEncoding optional | string | Encoding used when data is a string (default "utf8"). |
this — this for method chaining.Error— ifdigest()was already called, or withcode = "VAEL_CRYPTO_LIMIT"if cumulative input exceeds 16 MiB.TypeError— whendatahas an invalid type orinputEncodingis unknown (ERR_UNKNOWN_ENCODING).
Hmac.digest
Section titled “Hmac.digest”digest(): Uint8Array;
digest(encoding: DigestEncoding): string;
Compute raw digest bytes.
Finalizes the HMAC state; subsequent update() or digest() calls throw.
Compute encoded digest string.
Finalizes the HMAC state; subsequent update() or digest() calls throw.
| Name | Type | Description |
|---|---|---|
encoding optional | DigestEncoding | Output string encoding ("hex", "base64", "base64url", "latin1", or "binary"). |
Uint8Array— Raw HMAC tag bytes as aBuffer(Uint8Arraysubclass).string— Encoded HMAC tag string.
Error— ifdigest()was already called.TypeError— withcode = "ERR_UNKNOWN_ENCODING"whenencodingis unsupported.
CipherOptions
Section titled “CipherOptions”export interface CipherOptions {
authTagLength?: number;
}
Options accepted by createCipheriv and createDecipheriv.
| Property | Type | Description | Since |
|---|---|---|---|
authTagLength optional | number | Authentication tag byte length for AEAD ciphers (for example 16 for GCM). | v0.0.0-alpha.2 |
Cipher
Section titled “Cipher”export interface Cipher {
update(data: BinaryLike, inputEncoding?: string): Uint8Array;
update(
data: BinaryLike,
inputEncoding: string | undefined,
outputEncoding: DigestEncoding,
): string;
final(): Uint8Array;
final(outputEncoding: DigestEncoding): string;
setAutoPadding(autoPadding?: boolean): this;
setAAD?(buffer: ArrayBufferView, options?: { plaintextLength?: number }): this;
getAuthTag?(): Uint8Array;
}
Symmetric encryption cipher instance returned by createCipheriv.
Cipher.update
Section titled “Cipher.update”update(data: BinaryLike, inputEncoding?: string): Uint8Array;
update(
data: BinaryLike,
inputEncoding: string | undefined,
outputEncoding: DigestEncoding,
): string;
Encrypt data as raw bytes.
Encrypt data and encode ciphertext as a string.
| Name | Type | Description |
|---|---|---|
data | BinaryLike | — |
inputEncoding optional | string | string | undefined | — |
outputEncoding optional | DigestEncoding | — |
Uint8Arraystring
Cipher.final
Section titled “Cipher.final”final(): Uint8Array;
final(outputEncoding: DigestEncoding): string;
Finalize encryption and return remaining ciphertext bytes.
Finalize encryption and encode remaining ciphertext as a string.
| Name | Type | Description |
|---|---|---|
outputEncoding optional | DigestEncoding | — |
Uint8Arraystring
Cipher.setAutoPadding
Section titled “Cipher.setAutoPadding”setAutoPadding(autoPadding?: boolean): this;
Enable or disable PKCS#7 automatic padding for block ciphers.
| Name | Type | Description |
|---|---|---|
autoPadding optional | boolean | — |
thisCipher.setAAD
Section titled “Cipher.setAAD”setAAD?(buffer: ArrayBufferView, options?: { plaintextLength?: number }): this;
Supply additional authenticated data (AAD) for AEAD ciphers (GCM).
| Name | Type | Description |
|---|---|---|
buffer | ArrayBufferView | — |
options optional | { plaintextLength?: number } | — |
thisCipher.getAuthTag
Section titled “Cipher.getAuthTag”getAuthTag?(): Uint8Array;
Return the AEAD authentication tag after final().
Decipher
Section titled “Decipher”export interface Decipher {
update(data: BinaryLike, inputEncoding?: string): Uint8Array;
update(
data: BinaryLike,
inputEncoding: string | undefined,
outputEncoding: string,
): string;
final(): Uint8Array;
final(outputEncoding: string): string;
setAutoPadding(autoPadding?: boolean): this;
setAAD?(buffer: ArrayBufferView, options?: { plaintextLength?: number }): this;
setAuthTag?(buffer: ArrayBufferView): this;
}
Symmetric decryption decipher instance returned by createDecipheriv.
Decipher.update
Section titled “Decipher.update”update(data: BinaryLike, inputEncoding?: string): Uint8Array;
update(
data: BinaryLike,
inputEncoding: string | undefined,
outputEncoding: string,
): string;
Decrypt data as raw bytes.
Decrypt data and decode plaintext as a string.
| Name | Type | Description |
|---|---|---|
data | BinaryLike | — |
inputEncoding optional | string | string | undefined | — |
outputEncoding optional | string | — |
Uint8Arraystring
Decipher.final
Section titled “Decipher.final”final(): Uint8Array;
final(outputEncoding: string): string;
Finalize decryption and return remaining plaintext bytes.
Finalize decryption and decode remaining plaintext as a string.
| Name | Type | Description |
|---|---|---|
outputEncoding optional | string | — |
Uint8Arraystring
Decipher.setAutoPadding
Section titled “Decipher.setAutoPadding”setAutoPadding(autoPadding?: boolean): this;
Enable or disable PKCS#7 automatic padding for block ciphers.
| Name | Type | Description |
|---|---|---|
autoPadding optional | boolean | — |
thisDecipher.setAAD
Section titled “Decipher.setAAD”setAAD?(buffer: ArrayBufferView, options?: { plaintextLength?: number }): this;
Supply additional authenticated data (AAD) for AEAD ciphers (GCM).
| Name | Type | Description |
|---|---|---|
buffer | ArrayBufferView | — |
options optional | { plaintextLength?: number } | — |
thisDecipher.setAuthTag
Section titled “Decipher.setAuthTag”setAuthTag?(buffer: ArrayBufferView): this;
Set the expected AEAD authentication tag before calling final().
| Name | Type | Description |
|---|---|---|
buffer | ArrayBufferView | — |
thisScryptOptions
Section titled “ScryptOptions”export interface ScryptOptions {
N?: number;
cost?: number;
r?: number;
blockSize?: number;
p?: number;
parallelization?: number;
maxmem?: number;
}
Cost parameters accepted by scrypt() and scryptSync().
| Property | Type | Description | Since |
|---|---|---|---|
N optional | number | CPU/memory cost parameter (power of two, default 16384). | v0.0.0-alpha.2 |
cost optional | number | Alias for N. | v0.0.0-alpha.2 |
r optional | number | Block size parameter (default 8). | v0.0.0-alpha.2 |
blockSize optional | number | Alias for r. | v0.0.0-alpha.2 |
p optional | number | Parallelization parameter (default 1). | v0.0.0-alpha.2 |
parallelization optional | number | Alias for p. | v0.0.0-alpha.2 |
maxmem optional | number | Upper memory limit in bytes (default 32 * 1024 * 1024). | v0.0.0-alpha.2 |
WebCryptoKey
Section titled “WebCryptoKey”export interface WebCryptoKey {
readonly type: "secret" | "private" | "public";
readonly extractable: boolean;
readonly algorithm: Record<string, unknown>;
readonly usages: readonly string[];
}
Cryptographic key descriptor used by webcrypto.subtle.
| Property | Type | Description | Since |
|---|---|---|---|
type readonly | "secret" | "private" | "public" | Key type ("secret", "private", or "public"). | v0.0.0-alpha.2 |
extractable readonly | boolean | Whether raw key material can be exported. | v0.0.0-alpha.2 |
algorithm readonly | Record<string, unknown> | Algorithm metadata associated with this key. | v0.0.0-alpha.2 |
usages readonly | readonly string[] | Permitted key usages ("encrypt", "decrypt", "sign", "verify", etc.). | v0.0.0-alpha.2 |
WebCryptoKeyPair
Section titled “WebCryptoKeyPair”export interface WebCryptoKeyPair {
readonly publicKey: WebCryptoKey;
readonly privateKey: WebCryptoKey;
}
Key pair returned by webcrypto.subtle.generateKey for asymmetric algorithms.
| Property | Type | Description | Since |
|---|---|---|---|
publicKey readonly | WebCryptoKey | Public key handle. | v0.0.0-alpha.2 |
privateKey readonly | WebCryptoKey | Private key handle. | v0.0.0-alpha.2 |
WebSubtleCrypto
Section titled “WebSubtleCrypto”export interface WebSubtleCrypto {
digest(algorithm: string | { name: string }, data: ArrayBufferView | ArrayBuffer): Promise<ArrayBuffer>;
encrypt(
algorithm: string | Record<string, unknown>,
key: WebCryptoKey,
data: ArrayBufferView | ArrayBuffer,
): Promise<ArrayBuffer>;
decrypt(
algorithm: string | Record<string, unknown>,
key: WebCryptoKey,
data: ArrayBufferView | ArrayBuffer,
): Promise<ArrayBuffer>;
sign(
algorithm: string | Record<string, unknown>,
key: WebCryptoKey,
data: ArrayBufferView | ArrayBuffer,
): Promise<ArrayBuffer>;
verify(
algorithm: string | Record<string, unknown>,
key: WebCryptoKey,
signature: ArrayBufferView | ArrayBuffer,
data: ArrayBufferView | ArrayBuffer,
): Promise<boolean>;
deriveBits(
algorithm: string | Record<string, unknown>,
baseKey: WebCryptoKey,
length: number,
): Promise<ArrayBuffer>;
deriveKey(
algorithm: string | Record<string, unknown>,
baseKey: WebCryptoKey,
derivedKeyType: string | Record<string, unknown>,
extractable: boolean,
keyUsages: readonly string[],
): Promise<WebCryptoKey>;
generateKey(
algorithm: string | Record<string, unknown>,
extractable: boolean,
keyUsages: readonly string[],
): Promise<WebCryptoKey | WebCryptoKeyPair>;
importKey(
format: "raw" | "pkcs8" | "spki" | "jwk",
keyData: ArrayBufferView | ArrayBuffer | Record<string, unknown>,
algorithm: string | Record<string, unknown>,
extractable: boolean,
keyUsages: readonly string[],
): Promise<WebCryptoKey>;
exportKey(format: "raw" | "pkcs8" | "spki", key: WebCryptoKey): Promise<ArrayBuffer>;
exportKey(format: "jwk", key: WebCryptoKey): Promise<Record<string, unknown>>;
}
WebCrypto SubtleCrypto interface exposed on webcrypto.subtle.
WebSubtleCrypto.digest
Section titled “WebSubtleCrypto.digest”digest(algorithm: string | { name: string }, data: ArrayBufferView | ArrayBuffer): Promise<ArrayBuffer>;
Compute a cryptographic digest.
| Name | Type | Description |
|---|---|---|
algorithm | string | { name: string } | — |
data | ArrayBufferView | ArrayBuffer | — |
WebSubtleCrypto.encrypt
Section titled “WebSubtleCrypto.encrypt”encrypt(
algorithm: string | Record<string, unknown>,
key: WebCryptoKey,
data: ArrayBufferView | ArrayBuffer,
): Promise<ArrayBuffer>;
Encrypt data using key and algorithm.
| Name | Type | Description |
|---|---|---|
algorithm | string | Record<string, unknown> | — |
key | WebCryptoKey | — |
data | ArrayBufferView | ArrayBuffer | — |
WebSubtleCrypto.decrypt
Section titled “WebSubtleCrypto.decrypt”decrypt(
algorithm: string | Record<string, unknown>,
key: WebCryptoKey,
data: ArrayBufferView | ArrayBuffer,
): Promise<ArrayBuffer>;
Decrypt data using key and algorithm.
| Name | Type | Description |
|---|---|---|
algorithm | string | Record<string, unknown> | — |
key | WebCryptoKey | — |
data | ArrayBufferView | ArrayBuffer | — |
WebSubtleCrypto.sign
Section titled “WebSubtleCrypto.sign”sign(
algorithm: string | Record<string, unknown>,
key: WebCryptoKey,
data: ArrayBufferView | ArrayBuffer,
): Promise<ArrayBuffer>;
Generate a digital signature.
| Name | Type | Description |
|---|---|---|
algorithm | string | Record<string, unknown> | — |
key | WebCryptoKey | — |
data | ArrayBufferView | ArrayBuffer | — |
WebSubtleCrypto.verify
Section titled “WebSubtleCrypto.verify”verify(
algorithm: string | Record<string, unknown>,
key: WebCryptoKey,
signature: ArrayBufferView | ArrayBuffer,
data: ArrayBufferView | ArrayBuffer,
): Promise<boolean>;
Verify a digital signature.
| Name | Type | Description |
|---|---|---|
algorithm | string | Record<string, unknown> | — |
key | WebCryptoKey | — |
signature | ArrayBufferView | ArrayBuffer | — |
data | ArrayBufferView | ArrayBuffer | — |
Promise<boolean>WebSubtleCrypto.deriveBits
Section titled “WebSubtleCrypto.deriveBits”deriveBits(
algorithm: string | Record<string, unknown>,
baseKey: WebCryptoKey,
length: number,
): Promise<ArrayBuffer>;
Derive raw bits from a base key.
| Name | Type | Description |
|---|---|---|
algorithm | string | Record<string, unknown> | — |
baseKey | WebCryptoKey | — |
length | number | — |
WebSubtleCrypto.deriveKey
Section titled “WebSubtleCrypto.deriveKey”deriveKey(
algorithm: string | Record<string, unknown>,
baseKey: WebCryptoKey,
derivedKeyType: string | Record<string, unknown>,
extractable: boolean,
keyUsages: readonly string[],
): Promise<WebCryptoKey>;
Derive a WebCryptoKey from a base key.
| Name | Type | Description |
|---|---|---|
algorithm | string | Record<string, unknown> | — |
baseKey | WebCryptoKey | — |
derivedKeyType | string | Record<string, unknown> | — |
extractable | boolean | — |
keyUsages | readonly string[] | — |
WebSubtleCrypto.generateKey
Section titled “WebSubtleCrypto.generateKey”generateKey(
algorithm: string | Record<string, unknown>,
extractable: boolean,
keyUsages: readonly string[],
): Promise<WebCryptoKey | WebCryptoKeyPair>;
Generate a symmetric key or asymmetric key pair.
| Name | Type | Description |
|---|---|---|
algorithm | string | Record<string, unknown> | — |
extractable | boolean | — |
keyUsages | readonly string[] | — |
WebSubtleCrypto.importKey
Section titled “WebSubtleCrypto.importKey”importKey(
format: "raw" | "pkcs8" | "spki" | "jwk",
keyData: ArrayBufferView | ArrayBuffer | Record<string, unknown>,
algorithm: string | Record<string, unknown>,
extractable: boolean,
keyUsages: readonly string[],
): Promise<WebCryptoKey>;
Import raw, PKCS#8, SPKI, or JWK key material.
| Name | Type | Description |
|---|---|---|
format | "raw" | "pkcs8" | "spki" | "jwk" | — |
keyData | ArrayBufferView | ArrayBuffer | Record<string, unknown> | — |
algorithm | string | Record<string, unknown> | — |
extractable | boolean | — |
keyUsages | readonly string[] | — |
WebSubtleCrypto.exportKey
Section titled “WebSubtleCrypto.exportKey”exportKey(format: "raw" | "pkcs8" | "spki", key: WebCryptoKey): Promise<ArrayBuffer>;
exportKey(format: "jwk", key: WebCryptoKey): Promise<Record<string, unknown>>;
Export key material in raw, PKCS#8, SPKI, or JWK format.
Export key material in JWK format.
| Name | Type | Description |
|---|---|---|
format | "raw" | "pkcs8" | "spki" | "jwk" | — |
key | WebCryptoKey | — |
Promise<ArrayBuffer>Promise<Record<string, unknown>>
WebCrypto
Section titled “WebCrypto”export interface WebCrypto {
readonly subtle: WebSubtleCrypto;
getRandomValues<T extends ArrayBufferView>(typedArray: T): T;
randomUUID(): string;
}
Web Cryptography API object exposed as crypto.webcrypto.
| Property | Type | Description | Since |
|---|---|---|---|
subtle readonly | WebSubtleCrypto | Subtle cryptographic primitives interface. | v0.0.0-alpha.2 |
WebCrypto.getRandomValues
Section titled “WebCrypto.getRandomValues”getRandomValues<T extends ArrayBufferView>(typedArray: T): T;
Fill typedArray with cryptographically strong random values.
| Name | Type | Description |
|---|---|---|
typedArray | T | — |
TWebCrypto.randomUUID
Section titled “WebCrypto.randomUUID”randomUUID(): string;
Generate a random RFC 4122/9562 v4 UUID string.
stringType Aliases
Section titled “Type Aliases”DigestEncoding
Section titled “DigestEncoding”export type DigestEncoding = "hex" | "base64" | "base64url" | "latin1" | "binary";
Supported digest output encodings.
BinaryLike
Section titled “BinaryLike”export type BinaryLike = string | Uint8Array | ArrayBufferView;
Binary or string input accepted by Hash, Hmac, and pbkdf2Sync.
CryptoConstants
Section titled “CryptoConstants”export type CryptoConstants = Readonly<Record<string, number | string>>;
Cryptographic constants exposed on crypto.constants.
Constants
Section titled “Constants”webcrypto
Section titled “webcrypto”export const webcrypto: WebCrypto;
Web Cryptography API interface (subtle, getRandomValues, randomUUID).
constants
Section titled “constants”export const constants: CryptoConstants;
Cryptographic constants map.
Default Export
Section titled “Default Export”default export
Section titled “default export”const _default: {
/** Generate cryptographically strong random bytes. @since 0.0.0-alpha.0 */
randomBytes: typeof randomBytes;
/** Generate an RFC 4122/9562 v4 UUID string. @since 0.0.0-alpha.0 */
randomUUID: typeof randomUUID;
/** Create an incremental hash object. @since 0.0.0-alpha.0 */
createHash: typeof createHash;
/** Create an incremental HMAC object. @since 0.0.0-alpha.0 */
createHmac: typeof createHmac;
/** Derive a key using PBKDF2-HMAC. @since 0.0.0-alpha.0 */
pbkdf2Sync: typeof pbkdf2Sync;
/** Compare two equal-length buffers in constant time. @since 0.0.0-alpha.0 */
timingSafeEqual: typeof timingSafeEqual;
/** Create a symmetric encryption cipher. @since 0.0.0-alpha.2 */
createCipheriv: typeof createCipheriv;
/** Create a symmetric decryption decipher. @since 0.0.0-alpha.2 */
createDecipheriv: typeof createDecipheriv;
/** Synchronously derive a key using scrypt. @since 0.0.0-alpha.2 */
scryptSync: typeof scryptSync;
/** Asynchronously derive a key using scrypt. @since 0.0.0-alpha.2 */
scrypt: typeof scrypt;
/** Synchronously derive a key using HKDF. @since 0.0.0-alpha.2 */
hkdfSync: typeof hkdfSync;
/** Asynchronously derive a key using HKDF. @since 0.0.0-alpha.2 */
hkdf: typeof hkdf;
/** Asynchronously derive a key using PBKDF2-HMAC. @since 0.0.0-alpha.2 */
pbkdf2: typeof pbkdf2;
/** Compute a one-shot cryptographic hash. @since 0.0.0-alpha.2 */
hash: typeof hash;
/** Generate a uniformly distributed random integer. @since 0.0.0-alpha.2 */
randomInt: typeof randomInt;
/** Synchronously fill a buffer with random bytes. @since 0.0.0-alpha.2 */
randomFillSync: typeof randomFillSync;
/** Asynchronously fill a buffer with random bytes. @since 0.0.0-alpha.2 */
randomFill: typeof randomFill;
/** List supported hash algorithm names. @since 0.0.0-alpha.2 */
getHashes: typeof getHashes;
/** Web Cryptography API interface. @since 0.0.0-alpha.2 */
readonly webcrypto: WebCrypto;
/** Cryptographic constants. @since 0.0.0-alpha.2 */
readonly constants: CryptoConstants;
};
export default _default;
scrypt, hkdf, pbkdf2, randomFill are available in vjs (V8) only and omitted from the default export in vjs-lite.Default export object providing all node:crypto functions.
