Crypto

crypto.createSecretKey()

Wraps symmetric key material in a KeyObject. The wrapper is not a hardware vault; prevent accidental key exports and use a managed key lifecycle. The fixture generates a disposable key. Tested on Node.js 22.16.0. Example output (one line per entry): ["secret 32"].

Formal Syntax & Structure

nodejs syntaxnodejs
crypto.createSecretKey(key[, encoding])

Parameters & Attributes

NameTypeDescription
keystring | Buffer | TypedArray | DataView | ArrayBufferSecret bytes.
encodingstringEncoding of string key.

Return Value

KeyObject

Secret key wrapper.

Working Example

Example Snippetnodejs
import { createSecretKey, randomBytes } from 'node:crypto';const k = createSecretKey(randomBytes(32));console.log(k.type, k.symmetricKeySize);
Node.js Reference