Web Crypto

subtle.exportKey()

Serializes an extractable key. Exported secret material must be handled as sensitive data; this example only prints its length. Tested on Node.js 22.16.0. Example output (one line per entry): ["16"].

Formal Syntax & Structure

nodejs syntaxnodejs
subtle.exportKey(format, key)

Parameters & Attributes

NameTypeDescription
formatstringOutput format.
keyCryptoKeyExtractable key.

Return Value

Promise<ArrayBuffer | object>

Encoded key.

Working Example

Example Snippetnodejs
import { webcrypto as crypto } from 'node:crypto';const k = await crypto.subtle.generateKey({ name: 'AES-GCM', length: 128 }, true, ['encrypt']);console.log((await crypto.subtle.exportKey('raw', k)).byteLength);
Node.js Reference