Web Crypto
subtle.importKey()
Builds a CryptoKey from existing key material. The fixed bytes below are synthetic and must not be used as a real secret. Tested on Node.js 22.16.0. Example output (one line per entry): ["HMAC sign false"].
Formal Syntax & Structure
nodejs syntaxnodejs
subtle.importKey(format, keyData, algorithm, extractable, keyUsages)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| format | string | Key format. |
| keyData | BufferSource | object | Encoded key material. |
| algorithm | string | object | Key algorithm. |
| extractable | boolean | Export permission. |
| keyUsages | string[] | Allowed operations. |
Return Value
Promise<CryptoKey>
Imported key.
Working Example
Example Snippetnodejs
import { webcrypto as crypto } from 'node:crypto';const k = await crypto.subtle.importKey('raw', new Uint8Array(32).fill(7), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);console.log(k.algorithm.name, k.usages.join(','), k.extractable);