Skip to main content
webcrypto.SubtleCrypto.wrapKey - crypto - Node documentation
method webcrypto.SubtleCrypto.wrapKey

Usage in Deno

import { type webcrypto } from "node:crypto";
SubtleCrypto.wrapKey(): Promise<ArrayBuffer>

In cryptography, "wrapping a key" refers to exporting and then encrypting the keying material. The subtle.wrapKey() method exports the keying material into the format identified by format, then encrypts it using the method and parameters specified by wrapAlgo and the keying material provided by wrappingKey. It is the equivalent to calling subtle.exportKey() using format and key as the arguments, then passing the result to the subtle.encrypt() method using wrappingKey and wrapAlgo as inputs. If successful, the returned promise will be resolved with an <ArrayBuffer> containing the encrypted key data.

The wrapping algorithms currently supported include:

  • 'RSA-OAEP'
  • 'AES-CTR'
  • 'AES-CBC'
  • 'AES-GCM'
  • 'AES-KW'

Parameters

format: KeyFormat

Must be one of 'raw', 'pkcs8', 'spki', or 'jwk'.

wrappingKey: CryptoKey

Return Type

Promise<ArrayBuffer>