__JS_FLAVORED_DYNAMIC_CSS__
Skip to content
Table of contents

- Web Crypto API
  - Modern Algorithms in the Web Cryptography API
  - Secure Curves in the Web Cryptography API
  - Examples
    - Generating keys
      - AES keys
      - ECDSA key pairs
      - Ed25519/X25519 key pairs
      - HMAC keys
      - RSA key pairs
    - Encryption and decryption
    - Exporting and importing keys
    - Wrapping and unwrapping keys
    - Sign and verify
    - Deriving bits and keys
    - Digest
    - Checking for runtime algorithm support
  - Algorithm matrix
    - Key Management APIs
    - Crypto Operation APIs
  - Class: `Crypto`
    - `crypto.subtle`
    - `crypto.getRandomValues(typedArray)`
    - `crypto.randomUUID()`
  - Class: `CryptoKey`
    - `cryptoKey.algorithm`
    - `cryptoKey.extractable`
    - `cryptoKey.type`
    - `cryptoKey.usages`
  - Class: `CryptoKeyPair`
    - `cryptoKeyPair.privateKey`
    - `cryptoKeyPair.publicKey`
  - Class: `SubtleCrypto`
    - Static method: `SubtleCrypto.supports(operation, algorithm[, lengthOrAdditionalAlgorithm])`
    - `subtle.decapsulateBits(decapsulationAlgorithm, decapsulationKey, ciphertext)`
    - `subtle.decapsulateKey(decapsulationAlgorithm, decapsulationKey, ciphertext, sharedKeyAlgorithm, extractable, usages)`
    - `subtle.decrypt(algorithm, key, data)`
    - `subtle.deriveBits(algorithm, baseKey[, length])`
    - `subtle.deriveKey(algorithm, baseKey, derivedKeyAlgorithm, extractable, keyUsages)`
    - `subtle.digest(algorithm, data)`
    - `subtle.encapsulateBits(encapsulationAlgorithm, encapsulationKey)`
    - `subtle.encapsulateKey(encapsulationAlgorithm, encapsulationKey, sharedKeyAlgorithm, extractable, usages)`
    - `subtle.encrypt(algorithm, key, data)`
    - `subtle.exportKey(format, key)`
    - `subtle.getPublicKey(key, keyUsages)`
    - `subtle.generateKey(algorithm, extractable, keyUsages)`
    - `subtle.importKey(format, keyData, algorithm, extractable, keyUsages)`
    - `subtle.sign(algorithm, key, data)`
    - `subtle.unwrapKey(format, wrappedKey, unwrappingKey, unwrapAlgo, unwrappedKeyAlgo, extractable, keyUsages)`
    - `subtle.verify(algorithm, key, signature, data)`
    - `subtle.wrapKey(format, key, wrappingKey, wrapAlgo)`
  - Algorithm parameters
    - Class: `Algorithm`
      - `Algorithm.name`
    - Class: `AeadParams`
      - `aeadParams.additionalData`
      - `aeadParams.iv`
      - `aeadParams.name`
      - `aeadParams.tagLength`
    - Class: `AesDerivedKeyParams`
      - `aesDerivedKeyParams.name`
      - `aesDerivedKeyParams.length`
    - Class: `AesCbcParams`
      - `aesCbcParams.iv`
      - `aesCbcParams.name`
    - Class: `AesCtrParams`
      - `aesCtrParams.counter`
      - `aesCtrParams.length`
      - `aesCtrParams.name`
    - Class: `AesKeyAlgorithm`
      - `aesKeyAlgorithm.length`
      - `aesKeyAlgorithm.name`
    - Class: `AesKeyGenParams`
      - `aesKeyGenParams.length`
      - `aesKeyGenParams.name`
    - Class: `Argon2Params`
      - `argon2Params.associatedData`
      - `argon2Params.memory`
      - `argon2Params.name`
      - `argon2Params.nonce`
      - `argon2Params.parallelism`
      - `argon2Params.passes`
      - `argon2Params.secretValue`
      - `argon2Params.version`
    - Class: `ContextParams`
      - `contextParams.name`
      - `contextParams.context`
    - Class: `CShakeParams`
      - `cShakeParams.name`
      - `cShakeParams.outputLength`
      - `cShakeParams.functionName`
      - `cShakeParams.customization`
    - Class: `EcdhKeyDeriveParams`
      - `ecdhKeyDeriveParams.name`
      - `ecdhKeyDeriveParams.public`
    - Class: `EcdsaParams`
      - `ecdsaParams.hash`
      - `ecdsaParams.name`
    - Class: `EcKeyAlgorithm`
      - `ecKeyAlgorithm.name`
      - `ecKeyAlgorithm.namedCurve`
    - Class: `EcKeyGenParams`
      - `ecKeyGenParams.name`
      - `ecKeyGenParams.namedCurve`
    - Class: `EcKeyImportParams`
      - `ecKeyImportParams.name`
      - `ecKeyImportParams.namedCurve`
    - Class: `EncapsulatedBits`
      - `encapsulatedBits.ciphertext`
      - `encapsulatedBits.sharedKey`
    - Class: `EncapsulatedKey`
      - `encapsulatedKey.ciphertext`
      - `encapsulatedKey.sharedKey`
    - Class: `HkdfParams`
      - `hkdfParams.hash`
      - `hkdfParams.info`
      - `hkdfParams.name`
      - `hkdfParams.salt`
    - Class: `HmacImportParams`
      - `hmacImportParams.hash`
      - `hmacImportParams.length`
      - `hmacImportParams.name`
    - Class: `HmacKeyAlgorithm`
      - `hmacKeyAlgorithm.hash`
      - `hmacKeyAlgorithm.length`
      - `hmacKeyAlgorithm.name`
    - Class: `HmacKeyGenParams`
      - `hmacKeyGenParams.hash`
      - `hmacKeyGenParams.length`
      - `hmacKeyGenParams.name`
    - Class: `KeyAlgorithm`
      - `keyAlgorithm.name`
    - Class: `KmacImportParams`
      - `kmacImportParams.length`
      - `kmacImportParams.name`
    - Class: `KmacKeyAlgorithm`
      - `kmacKeyAlgorithm.length`
      - `kmacKeyAlgorithm.name`
    - Class: `KmacKeyGenParams`
      - `kmacKeyGenParams.length`
      - `kmacKeyGenParams.name`
    - Class: `KmacParams`
      - `kmacParams.algorithm`
      - `kmacParams.outputLength`
      - `kmacParams.customization`
    - Class: `Pbkdf2Params`
      - `pbkdf2Params.hash`
      - `pbkdf2Params.iterations`
      - `pbkdf2Params.name`
      - `pbkdf2Params.salt`
    - Class: `RsaHashedImportParams`
      - `rsaHashedImportParams.hash`
      - `rsaHashedImportParams.name`
    - Class: `RsaHashedKeyAlgorithm`
      - `rsaHashedKeyAlgorithm.hash`
      - `rsaHashedKeyAlgorithm.modulusLength`
      - `rsaHashedKeyAlgorithm.name`
      - `rsaHashedKeyAlgorithm.publicExponent`
    - Class: `RsaHashedKeyGenParams`
      - `rsaHashedKeyGenParams.hash`
      - `rsaHashedKeyGenParams.modulusLength`
      - `rsaHashedKeyGenParams.name`
      - `rsaHashedKeyGenParams.publicExponent`
    - Class: `RsaOaepParams`
      - `rsaOaepParams.label`
      - `rsaOaepParams.name`
    - Class: `RsaPssParams`
      - `rsaPssParams.name`
      - `rsaPssParams.saltLength`

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.8.0 | KMAC algorithms are now supported.
v24.8.0 | Argon2 algorithms are now supported.
v24.7.0 | AES-OCB algorithm is now supported.
v24.7.0 | ML-KEM algorithms are now supported.
v24.7.0 | ChaCha20-Poly1305 algorithm is now supported.
v24.7.0 | SHA-3 algorithms are now supported.
v24.7.0 | SHAKE algorithms are now supported.
v24.7.0 | ML-DSA algorithms are now supported.
v23.5.0, v22.13.0 | Algorithms `Ed25519` and `X25519` are now stable.
v19.0.0 | No longer experimental except for the `Ed25519`, `Ed448`, `X25519`, and `X448` algorithms.
v20.0.0, v18.17.0 | Arguments are now coerced and validated as per their WebIDL definitions like in other Web Crypto API implementations.
v18.4.0, v16.17.0 | Removed proprietary `'node.keyObject'` import/export format.
v18.4.0, v16.17.0 | Removed proprietary `'NODE-DSA'`, `'NODE-DH'`, and `'NODE-SCRYPT'` algorithms.
v18.4.0, v16.17.0 | Added `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'` algorithms.
v18.4.0, v16.17.0 | Removed proprietary `'NODE-ED25519'` and `'NODE-ED448'` algorithms.
v18.4.0, v16.17.0 | Removed proprietary `'NODE-X25519'` and `'NODE-X448'` named curves from the `'ECDH'` algorithm.

> Stability: 2 - Stable

Node.js provides an implementation of the Web Crypto API standard.

Use `globalThis.crypto` or `require('node:crypto').webcrypto` to access this module.

    const { subtle } = globalThis.crypto;

    (async function() {

      const key = await subtle.generateKey({
        name: 'HMAC',
        hash: 'SHA-256',
        length: 256,
      }, true, ['sign', 'verify']);

      const enc = new TextEncoder();
      const message = enc.encode('I love cupcakes');

      const digest = await subtle.sign({
        name: 'HMAC',
      }, key, message);

    })();

<hundefined>[object Object]</hundefined>

> Stability: 1.1 - Active development

Node.js provides an implementation of the following features from the Modern Algorithms in the Web Cryptography API WICG proposal:

Algorithms:

- `'AES-OCB'`[^openssl30]
- `'Argon2d'`[^openssl32]
- `'Argon2i'`[^openssl32]
- `'Argon2id'`[^openssl32]
- `'ChaCha20-Poly1305'`
- `'cSHAKE128'`
- `'cSHAKE256'`
- `'KMAC128'`[^openssl30]
- `'KMAC256'`[^openssl30]
- `'ML-DSA-44'`[^openssl35]
- `'ML-DSA-65'`[^openssl35]
- `'ML-DSA-87'`[^openssl35]
- `'ML-KEM-512'`[^openssl35]
- `'ML-KEM-768'`[^openssl35]
- `'ML-KEM-1024'`[^openssl35]
- `'SHA3-256'`
- `'SHA3-384'`
- `'SHA3-512'`

Key Formats:

- `'raw-public'`
- `'raw-secret'`
- `'raw-seed'`

Methods:

- `subtle.decapsulateBits()`
- `subtle.decapsulateKey()`
- `subtle.encapsulateBits()`
- `subtle.encapsulateKey()`
- `subtle.getPublicKey()`
- `SubtleCrypto.supports()`

<hundefined>[object Object]</hundefined>

> Stability: 1.1 - Active development

Node.js provides an implementation of the following features from the Secure Curves in the Web Cryptography API WICG proposal:

Algorithms:

- `'Ed448'`
- `'X448'`

<hundefined>[object Object]</hundefined> <hundefined>[object Object]</hundefined>

The <a href="webcrypto.html#class-subtlecrypto" class="type"><SubtleCrypto></a> class can be used to generate symmetric (secret) keys or asymmetric key pairs (public key and private key).

<hundefined>[object Object]</hundefined>

    const { subtle } = globalThis.crypto;

    async function generateAesKey(length = 256) {
      const key = await subtle.generateKey({
        name: 'AES-CBC',
        length,
      }, true, ['encrypt', 'decrypt']);

      return key;
    }

<hundefined>[object Object]</hundefined>

    const { subtle } = globalThis.crypto;

    async function generateEcKey(namedCurve = 'P-521') {
      const {
        publicKey,
        privateKey,
      } = await subtle.generateKey({
        name: 'ECDSA',
        namedCurve,
      }, true, ['sign', 'verify']);

      return { publicKey, privateKey };
    }

<hundefined>[object Object]</hundefined>

    const { subtle } = globalThis.crypto;

    async function generateEd25519Key() {
      return subtle.generateKey({
        name: 'Ed25519',
      }, true, ['sign', 'verify']);
    }

    async function generateX25519Key() {
      return subtle.generateKey({
        name: 'X25519',
      }, true, ['deriveKey']);
    }

<hundefined>[object Object]</hundefined>

    const { subtle } = globalThis.crypto;

    async function generateHmacKey(hash = 'SHA-256') {
      const key = await subtle.generateKey({
        name: 'HMAC',
        hash,
      }, true, ['sign', 'verify']);

      return key;
    }

<hundefined>[object Object]</hundefined>

    const { subtle } = globalThis.crypto;
    const publicExponent = new Uint8Array([1, 0, 1]);

    async function generateRsaKey(modulusLength = 2048, hash = 'SHA-256') {
      const {
        publicKey,
        privateKey,
      } = await subtle.generateKey({
        name: 'RSASSA-PKCS1-v1_5',
        modulusLength,
        publicExponent,
        hash,
      }, true, ['sign', 'verify']);

      return { publicKey, privateKey };
    }

<hundefined>[object Object]</hundefined>

    const crypto = globalThis.crypto;

    async function aesEncrypt(plaintext) {
      const ec = new TextEncoder();
      const key = await generateAesKey();
      const iv = crypto.getRandomValues(new Uint8Array(16));

      const ciphertext = await crypto.subtle.encrypt({
        name: 'AES-CBC',
        iv,
      }, key, ec.encode(plaintext));

      return {
        key,
        iv,
        ciphertext,
      };
    }

    async function aesDecrypt(ciphertext, key, iv) {
      const dec = new TextDecoder();
      const plaintext = await crypto.subtle.decrypt({
        name: 'AES-CBC',
        iv,
      }, key, ciphertext);

      return dec.decode(plaintext);
    }

<hundefined>[object Object]</hundefined>

    const { subtle } = globalThis.crypto;

    async function generateAndExportHmacKey(format = 'jwk', hash = 'SHA-512') {
      const key = await subtle.generateKey({
        name: 'HMAC',
        hash,
      }, true, ['sign', 'verify']);

      return subtle.exportKey(format, key);
    }

    async function importHmacKey(keyData, format = 'jwk', hash = 'SHA-512') {
      const key = await subtle.importKey(format, keyData, {
        name: 'HMAC',
        hash,
      }, true, ['sign', 'verify']);

      return key;
    }

<hundefined>[object Object]</hundefined>

    const { subtle } = globalThis.crypto;

    async function generateAndWrapHmacKey(format = 'jwk', hash = 'SHA-512') {
      const [
        key,
        wrappingKey,
      ] = await Promise.all([
        subtle.generateKey({
          name: 'HMAC', hash,
        }, true, ['sign', 'verify']),
        subtle.generateKey({
          name: 'AES-KW',
          length: 256,
        }, true, ['wrapKey', 'unwrapKey']),
      ]);

      const wrappedKey = await subtle.wrapKey(format, key, wrappingKey, 'AES-KW');

      return { wrappedKey, wrappingKey };
    }

    async function unwrapHmacKey(
      wrappedKey,
      wrappingKey,
      format = 'jwk',
      hash = 'SHA-512') {

      const key = await subtle.unwrapKey(
        format,
        wrappedKey,
        wrappingKey,
        'AES-KW',
        { name: 'HMAC', hash },
        true,
        ['sign', 'verify']);

      return key;
    }

<hundefined>[object Object]</hundefined>

    const { subtle } = globalThis.crypto;

    async function sign(key, data) {
      const ec = new TextEncoder();
      const signature =
        await subtle.sign('RSASSA-PKCS1-v1_5', key, ec.encode(data));
      return signature;
    }

    async function verify(key, signature, data) {
      const ec = new TextEncoder();
      const verified =
        await subtle.verify(
          'RSASSA-PKCS1-v1_5',
          key,
          signature,
          ec.encode(data));
      return verified;
    }

<hundefined>[object Object]</hundefined>

    const { subtle } = globalThis.crypto;

    async function pbkdf2(pass, salt, iterations = 1000, length = 256) {
      const ec = new TextEncoder();
      const key = await subtle.importKey(
        'raw',
        ec.encode(pass),
        'PBKDF2',
        false,
        ['deriveBits']);
      const bits = await subtle.deriveBits({
        name: 'PBKDF2',
        hash: 'SHA-512',
        salt: ec.encode(salt),
        iterations,
      }, key, length);
      return bits;
    }

    async function pbkdf2Key(pass, salt, iterations = 1000, length = 256) {
      const ec = new TextEncoder();
      const keyMaterial = await subtle.importKey(
        'raw',
        ec.encode(pass),
        'PBKDF2',
        false,
        ['deriveKey']);
      const key = await subtle.deriveKey({
        name: 'PBKDF2',
        hash: 'SHA-512',
        salt: ec.encode(salt),
        iterations,
      }, keyMaterial, {
        name: 'AES-GCM',
        length,
      }, true, ['encrypt', 'decrypt']);
      return key;
    }

<hundefined>[object Object]</hundefined>

    const { subtle } = globalThis.crypto;

    async function digest(data, algorithm = 'SHA-512') {
      const ec = new TextEncoder();
      const digest = await subtle.digest(algorithm, ec.encode(data));
      return digest;
    }

<hundefined>[object Object]</hundefined>

`SubtleCrypto.supports()` allows feature detection in Web Crypto API, which can be used to detect whether a given algorithm identifier (including its parameters) is supported for the given operation.

This example derives a key from a password using Argon2, if available, or PBKDF2, otherwise; and then encrypts and decrypts some text with it using AES-OCB, if available, and AES-GCM, otherwise.

    const { SubtleCrypto, crypto } = globalThis;

    const password = 'correct horse battery staple';
    const derivationAlg =
      SubtleCrypto.supports?.('importKey', 'Argon2id') ?
        'Argon2id' :
        'PBKDF2';
    const encryptionAlg =
      SubtleCrypto.supports?.('importKey', 'AES-OCB') ?
        'AES-OCB' :
        'AES-GCM';
    const passwordKey = await crypto.subtle.importKey(
      derivationAlg === 'Argon2id' ? 'raw-secret' : 'raw',
      new TextEncoder().encode(password),
      derivationAlg,
      false,
      ['deriveKey'],
    );
    const nonce = crypto.getRandomValues(new Uint8Array(16));
    const derivationParams =
      derivationAlg === 'Argon2id' ?
        {
          nonce,
          parallelism: 4,
          memory: 2 ** 21,
          passes: 1,
        } :
        {
          salt: nonce,
          iterations: 100_000,
          hash: 'SHA-256',
        };
    const key = await crypto.subtle.deriveKey(
      {
        name: derivationAlg,
        ...derivationParams,
      },
      passwordKey,
      {
        name: encryptionAlg,
        length: 256,
      },
      false,
      ['encrypt', 'decrypt'],
    );
    const plaintext = 'Hello, world!';
    const iv = crypto.getRandomValues(new Uint8Array(16));
    const encrypted = await crypto.subtle.encrypt(
      { name: encryptionAlg, iv },
      key,
      new TextEncoder().encode(plaintext),
    );
    const decrypted = new TextDecoder().decode(await crypto.subtle.decrypt(
      { name: encryptionAlg, iv },
      key,
      encrypted,
    ));

<hundefined>[object Object]</hundefined>

The following tables detail the algorithms supported by the Node.js Web Crypto API implementation and the APIs supported for each:

<hundefined>[object Object]</hundefined>

Algorithm | `subtle.generateKey()` | `subtle.exportKey()` | `subtle.importKey()` | `subtle.getPublicKey()`
--- | --- | --- | --- | ---
`'AES-CBC'` | ✔ | ✔ | ✔ |
`'AES-CTR'` | ✔ | ✔ | ✔ |
`'AES-GCM'` | ✔ | ✔ | ✔ |
`'AES-KW'` | ✔ | ✔ | ✔ |
`'AES-OCB'` | ✔ | ✔ | ✔ |
`'Argon2d'` |  |  | ✔ |
`'Argon2i'` |  |  | ✔ |
`'Argon2id'` |  |  | ✔ |
`'ChaCha20-Poly1305'`[^modern-algos] | ✔ | ✔ | ✔ |
`'ECDH'` | ✔ | ✔ | ✔ | ✔
`'ECDSA'` | ✔ | ✔ | ✔ | ✔
`'Ed25519'` | ✔ | ✔ | ✔ | ✔
`'Ed448'`[^secure-curves] | ✔ | ✔ | ✔ | ✔
`'HKDF'` |  |  | ✔ |
`'HMAC'` | ✔ | ✔ | ✔ |
`'KMAC128'`[^modern-algos] | ✔ | ✔ | ✔ |
`'KMAC256'`[^modern-algos] | ✔ | ✔ | ✔ |
`'ML-DSA-44'`[^modern-algos] | ✔ | ✔ | ✔ | ✔
`'ML-DSA-65'`[^modern-algos] | ✔ | ✔ | ✔ | ✔
`'ML-DSA-87'`[^modern-algos] | ✔ | ✔ | ✔ | ✔
`'ML-KEM-512'`[^modern-algos] | ✔ | ✔ | ✔ | ✔
`'ML-KEM-768'`[^modern-algos] | ✔ | ✔ | ✔ | ✔
`'ML-KEM-1024'`[^modern-algos] | ✔ | ✔ | ✔ | ✔
`'PBKDF2'` |  |  | ✔ |
`'RSA-OAEP'` | ✔ | ✔ | ✔ | ✔
`'RSA-PSS'` | ✔ | ✔ | ✔ | ✔
`'RSASSA-PKCS1-v1_5'` | ✔ | ✔ | ✔ | ✔
`'X25519'` | ✔ | ✔ | ✔ | ✔
`'X448'`[^secure-curves] | ✔ | ✔ | ✔ | ✔

<hundefined>[object Object]</hundefined>

Column Legend:

- Encryption: `subtle.encrypt()` / `subtle.decrypt()`
- Signatures and MAC: `subtle.sign()` / `subtle.verify()`
- Key or Bits Derivation: `subtle.deriveBits()` / `subtle.deriveKey()`
- Key Wrapping: `subtle.wrapKey()` / `subtle.unwrapKey()`
- Key Encapsulation: `subtle.encapsulateBits()` / `subtle.decapsulateBits()` / `subtle.encapsulateKey()` / `subtle.decapsulateKey()`
- Digest: `subtle.digest()`

Algorithm | Encryption | Signatures and MAC | Key or Bits Derivation | Key Wrapping | Key Encapsulation | Digest
--- | --- | --- | --- | --- | --- | ---
`'AES-CBC'` | ✔ |  |  | ✔ |  |
`'AES-CTR'` | ✔ |  |  | ✔ |  |
`'AES-GCM'` | ✔ |  |  | ✔ |  |
`'AES-KW'` |  |  |  | ✔ |  |
`'AES-OCB'` | ✔ |  |  | ✔ |  |
`'Argon2d'` |  |  | ✔ |  |  |
`'Argon2i'` |  |  | ✔ |  |  |
`'Argon2id'` |  |  | ✔ |  |  |
`'ChaCha20-Poly1305'`[^modern-algos] | ✔ |  |  | ✔ |  |
`'cSHAKE128'`[^modern-algos] |  |  |  |  |  | ✔
`'cSHAKE256'`[^modern-algos] |  |  |  |  |  | ✔
`'ECDH'` |  |  | ✔ |  |  |
`'ECDSA'` |  | ✔ |  |  |  |
`'Ed25519'` |  | ✔ |  |  |  |
`'Ed448'`[^secure-curves] |  | ✔ |  |  |  |
`'HKDF'` |  |  | ✔ |  |  |
`'HMAC'` |  | ✔ |  |  |  |
`'KMAC128'`[^modern-algos] |  | ✔ |  |  |  |
`'KMAC256'`[^modern-algos] |  | ✔ |  |  |  |
`'ML-DSA-44'`[^modern-algos] |  | ✔ |  |  |  |
`'ML-DSA-65'`[^modern-algos] |  | ✔ |  |  |  |
`'ML-DSA-87'`[^modern-algos] |  | ✔ |  |  |  |
`'ML-KEM-512'`[^modern-algos] |  |  |  |  | ✔ |
`'ML-KEM-768'`[^modern-algos] |  |  |  |  | ✔ |
`'ML-KEM-1024'`[^modern-algos] |  |  |  |  | ✔ |
`'PBKDF2'` |  |  | ✔ |  |  |
`'RSA-OAEP'` | ✔ |  |  | ✔ |  |
`'RSA-PSS'` |  | ✔ |  |  |  |
`'RSASSA-PKCS1-v1_5'` |  | ✔ |  |  |  |
`'SHA-1'` |  |  |  |  |  | ✔
`'SHA-256'` |  |  |  |  |  | ✔
`'SHA-384'` |  |  |  |  |  | ✔
`'SHA-512'` |  |  |  |  |  | ✔
`'SHA3-256'`[^modern-algos] |  |  |  |  |  | ✔
`'SHA3-384'`[^modern-algos] |  |  |  |  |  | ✔
`'SHA3-512'`[^modern-algos] |  |  |  |  |  | ✔
`'X25519'` |  |  | ✔ |  |  |
`'X448'`[^secure-curves] |  |  | ✔ |  |  |

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

`globalThis.crypto` is an instance of the `Crypto` class. `Crypto` is a singleton that provides access to the remainder of the crypto API.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="webcrypto.html#class-subtlecrypto" class="type"><SubtleCrypto></a>

Provides access to the `SubtleCrypto` API.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- `typedArray` <a href="buffer.html#class-buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a>
- Returns: <a href="buffer.html#class-buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a>

Generates cryptographically strong random values. The given `typedArray` is filled with random values, and a reference to `typedArray` is returned.

The given `typedArray` must be an integer-based instance of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a>, i.e. `Float32Array` and `Float64Array` are not accepted.

An error will be thrown if the given `typedArray` is larger than 65,536 bytes.

<hundefined>[object Object]</hundefined>
Added in: v16.7.0

- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>

Generates a random RFC 4122 version 4 UUID. The UUID is generated using a cryptographic pseudorandom number generator.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="webcrypto.html#class-keyalgorithm" class="type"><KeyAlgorithm></a> | <a href="webcrypto.html#class-rsahashedkeyalgorithm" class="type"><RsaHashedKeyAlgorithm></a> | <a href="webcrypto.html#class-eckeyalgorithm" class="type"><EcKeyAlgorithm></a> | <a href="webcrypto.html#class-aeskeyalgorithm" class="type"><AesKeyAlgorithm></a> | <a href="webcrypto.html#class-hmackeyalgorithm" class="type"><HmacKeyAlgorithm></a> | <a href="webcrypto.html#class-kmackeyalgorithm" class="type"><KmacKeyAlgorithm></a>

An object detailing the algorithm for which the key can be used along with additional algorithm-specific parameters.

Read-only.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type" class="type"><boolean></a>

When `true`, the <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> can be extracted using either `subtle.exportKey()` or `subtle.wrapKey()`.

Read-only.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> One of `'secret'`, `'private'`, or `'public'`.

A string identifying whether the key is a symmetric (`'secret'`) or asymmetric (`'private'` or `'public'`) key.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string[]></a>

An array of strings identifying the operations for which the key may be used.

The possible usages are:

- `'encrypt'` - Enable using the key with `subtle.encrypt()`
- `'decrypt'` - Enable using the key with `subtle.decrypt()`
- `'sign'` - Enable using the key with `subtle.sign()`
- `'verify'` - Enable using the key with `subtle.verify()`
- `'deriveKey'` - Enable using the key with `subtle.deriveKey()`
- `'deriveBits'` - Enable using the key with `subtle.deriveBits()`
- `'encapsulateBits'` - Enable using the key with `subtle.encapsulateBits()`
- `'decapsulateBits'` - Enable using the key with `subtle.decapsulateBits()`
- `'encapsulateKey'` - Enable using the key with `subtle.encapsulateKey()`
- `'decapsulateKey'` - Enable using the key with `subtle.decapsulateKey()`
- `'wrapKey'` - Enable using the key with `subtle.wrapKey()`
- `'unwrapKey'` - Enable using the key with `subtle.unwrapKey()`

Valid key usages depend on the key algorithm (identified by `cryptokey.algorithm.name`).

Column Legend:

- Encryption: `subtle.encrypt()` / `subtle.decrypt()`
- Signatures and MAC: `subtle.sign()` / `subtle.verify()`
- Key or Bits Derivation: `subtle.deriveBits()` / `subtle.deriveKey()`
- Key Wrapping: `subtle.wrapKey()` / `subtle.unwrapKey()`
- Key Encapsulation: `subtle.encapsulateBits()` / `subtle.decapsulateBits()` / `subtle.encapsulateKey()` / `subtle.decapsulateKey()`

Supported Key Algorithm | Encryption | Signatures and MAC | Key or Bits Derivation | Key Wrapping | Key Encapsulation
--- | --- | --- | --- | --- | ---
`'AES-CBC'` | ✔ |  |  | ✔ |
`'AES-CTR'` | ✔ |  |  | ✔ |
`'AES-GCM'` | ✔ |  |  | ✔ |
`'AES-KW'` |  |  |  | ✔ |
`'AES-OCB'` | ✔ |  |  | ✔ |
`'Argon2d'` |  |  | ✔ |  |
`'Argon2i'` |  |  | ✔ |  |
`'Argon2id'` |  |  | ✔ |  |
`'ChaCha20-Poly1305'`[^modern-algos] | ✔ |  |  | ✔ |
`'ECDH'` |  |  | ✔ |  |
`'ECDSA'` |  | ✔ |  |  |
`'Ed25519'` |  | ✔ |  |  |
`'Ed448'`[^secure-curves] |  | ✔ |  |  |
`'HKDF'` |  |  | ✔ |  |
`'HMAC'` |  | ✔ |  |  |
`'KMAC128'`[^modern-algos] |  | ✔ |  |  |
`'KMAC256'`[^modern-algos] |  | ✔ |  |  |
`'ML-DSA-44'`[^modern-algos] |  | ✔ |  |  |
`'ML-DSA-65'`[^modern-algos] |  | ✔ |  |  |
`'ML-DSA-87'`[^modern-algos] |  | ✔ |  |  |
`'ML-KEM-512'`[^modern-algos] |  |  |  |  | ✔
`'ML-KEM-768'`[^modern-algos] |  |  |  |  | ✔
`'ML-KEM-1024'`[^modern-algos] |  |  |  |  | ✔
`'PBKDF2'` |  |  | ✔ |  |
`'RSA-OAEP'` | ✔ |  |  | ✔ |
`'RSA-PSS'` |  | ✔ |  |  |
`'RSASSA-PKCS1-v1_5'` |  | ✔ |  |  |
`'X25519'` |  |  | ✔ |  |
`'X448'`[^secure-curves] |  |  | ✔ |  |

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

The `CryptoKeyPair` is a simple dictionary object with `publicKey` and `privateKey` properties, representing an asymmetric key pair.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> A <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> whose `type` will be `'private'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> A <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> whose `type` will be `'public'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v24.7.0

> Stability: 1.1 - Active development

- `operation` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> "encrypt", "decrypt", "sign", "verify", "digest", "generateKey", "deriveKey", "deriveBits", "importKey", "exportKey", "getPublicKey", "wrapKey", "unwrapKey", "encapsulateBits", "encapsulateKey", "decapsulateBits", or "decapsulateKey"
- `algorithm` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>
- `lengthOrAdditionalAlgorithm` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type" class="type"><null></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type" class="type"><undefined></a> Depending on the operation this is either ignored, the value of the length argument when operation is "deriveBits", the algorithm of key to be derived when operation is "deriveKey", the algorithm of key to be exported before wrapping when operation is "wrapKey", the algorithm of key to be imported after unwrapping when operation is "unwrapKey", or the algorithm of key to be imported after en/decapsulating a key when operation is "encapsulateKey" or "decapsulateKey". Default: `null` when operation is "deriveBits", `undefined` otherwise.
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type" class="type"><boolean></a> Indicating whether the implementation supports the given operation

Allows feature detection in Web Crypto API, which can be used to detect whether a given algorithm identifier (including its parameters) is supported for the given operation.

See Checking for runtime algorithm support for an example use of this method.

<hundefined>[object Object]</hundefined>
Added in: v24.7.0

> Stability: 1.1 - Active development

- `decapsulationAlgorithm` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>
- `decapsulationKey` <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>
- `ciphertext` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> upon success.

A message recipient uses their asymmetric private key to decrypt an "encapsulated key" (ciphertext), thereby recovering a temporary symmetric key (represented as <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a>) which is then used to decrypt a message.

The algorithms currently supported include:

- `'ML-KEM-512'`[^modern-algos]
- `'ML-KEM-768'`[^modern-algos]
- `'ML-KEM-1024'`[^modern-algos]

<hundefined>[object Object]</hundefined>
Added in: v24.7.0

> Stability: 1.1 - Active development

- `decapsulationAlgorithm` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>
- `decapsulationKey` <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>
- `ciphertext` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>
- `sharedKeyAlgorithm` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a> | <a href="webcrypto.html#class-hmacimportparams" class="type"><HmacImportParams></a> | <a href="webcrypto.html#class-aesderivedkeyparams" class="type"><AesDerivedKeyParams></a> | <a href="webcrypto.html#class-kmacimportparams" class="type"><KmacImportParams></a>
- `extractable` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type" class="type"><boolean></a>
- `usages` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string[]></a> See Key usages.
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> upon success.

A message recipient uses their asymmetric private key to decrypt an "encapsulated key" (ciphertext), thereby recovering a temporary symmetric key (represented as <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>) which is then used to decrypt a message.

The algorithms currently supported include:

- `'ML-KEM-512'`[^modern-algos]
- `'ML-KEM-768'`[^modern-algos]
- `'ML-KEM-1024'`[^modern-algos]

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.7.0 | AES-OCB algorithm is now supported.
v24.7.0 | ChaCha20-Poly1305 algorithm is now supported.
v15.0.0 | Added in: v15.0.0

- `algorithm` <a href="webcrypto.html#class-rsaoaepparams" class="type"><RsaOaepParams></a> | <a href="webcrypto.html#class-aesctrparams" class="type"><AesCtrParams></a> | <a href="webcrypto.html#class-aescbcparams" class="type"><AesCbcParams></a> | <a href="webcrypto.html#class-aeadparams" class="type"><AeadParams></a>
- `key` <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>
- `data` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> upon success.

Using the method and parameters specified in `algorithm` and the keying material provided by `key`, this method attempts to decipher the provided `data`. If successful, the returned promise will be resolved with an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> containing the plaintext result.

The algorithms currently supported include:

- `'AES-CBC'`
- `'AES-CTR'`
- `'AES-GCM'`
- `'AES-OCB'`[^modern-algos]
- `'ChaCha20-Poly1305'`[^modern-algos]
- `'RSA-OAEP'`

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.8.0 | Argon2 algorithms are now supported.
v22.5.0, v20.17.0, v18.20.5 | The length parameter is now optional for `'ECDH'`, `'X25519'`, and `'X448'`.
v18.4.0, v16.17.0 | Added `'X25519'`, and `'X448'` algorithms.
v15.0.0 | Added in: v15.0.0

- `algorithm` <a href="webcrypto.html#class-ecdhkeyderiveparams" class="type"><EcdhKeyDeriveParams></a> | <a href="webcrypto.html#class-hkdfparams" class="type"><HkdfParams></a> | <a href="webcrypto.html#class-pbkdf2params" class="type"><Pbkdf2Params></a> | <a href="webcrypto.html#class-argon2params" class="type"><Argon2Params></a>
- `baseKey` <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>
- `length` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type" class="type"><null></a> Default: `null`
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> upon success.

Using the method and parameters specified in `algorithm` and the keying material provided by `baseKey`, this method attempts to generate `length` bits.

When `length` is not provided or `null` the maximum number of bits for a given algorithm is generated. This is allowed for the `'ECDH'`, `'X25519'`, and `'X448'`[^secure-curves] algorithms, for other algorithms `length` is required to be a number.

If successful, the returned promise will be resolved with an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> containing the generated data.

The algorithms currently supported include:

- `'Argon2d'`[^modern-algos]
- `'Argon2i'`[^modern-algos]
- `'Argon2id'`[^modern-algos]
- `'ECDH'`
- `'HKDF'`
- `'PBKDF2'`
- `'X25519'`
- `'X448'`[^secure-curves]

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.8.0 | Argon2 algorithms are now supported.
v18.4.0, v16.17.0 | Added `'X25519'`, and `'X448'` algorithms.
v15.0.0 | Added in: v15.0.0

- `algorithm` <a href="webcrypto.html#class-ecdhkeyderiveparams" class="type"><EcdhKeyDeriveParams></a> | <a href="webcrypto.html#class-hkdfparams" class="type"><HkdfParams></a> | <a href="webcrypto.html#class-pbkdf2params" class="type"><Pbkdf2Params></a> | <a href="webcrypto.html#class-argon2params" class="type"><Argon2Params></a>
- `baseKey` <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>
- `derivedKeyAlgorithm` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a> | <a href="webcrypto.html#class-hmacimportparams" class="type"><HmacImportParams></a> | <a href="webcrypto.html#class-aesderivedkeyparams" class="type"><AesDerivedKeyParams></a> | <a href="webcrypto.html#class-kmacimportparams" class="type"><KmacImportParams></a>
- `extractable` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type" class="type"><boolean></a>
- `keyUsages` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string[]></a> See Key usages.
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with a <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> upon success.

Using the method and parameters specified in `algorithm`, and the keying material provided by `baseKey`, this method attempts to generate a new <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> based on the method and parameters in `derivedKeyAlgorithm`.

Calling this method is equivalent to calling `subtle.deriveBits()` to generate raw keying material, then passing the result into the `subtle.importKey()` method using the `derivedKeyAlgorithm`, `extractable`, and `keyUsages` parameters as input.

The algorithms currently supported include:

- `'Argon2d'`[^modern-algos]
- `'Argon2i'`[^modern-algos]
- `'Argon2id'`[^modern-algos]
- `'ECDH'`
- `'HKDF'`
- `'PBKDF2'`
- `'X25519'`
- `'X448'`[^secure-curves]

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.7.0 | SHA-3 algorithms are now supported.
v24.7.0 | SHAKE algorithms are now supported.
v15.0.0 | Added in: v15.0.0

- `algorithm` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a> | <a href="webcrypto.html#class-cshakeparams" class="type"><CShakeParams></a>
- `data` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> upon success.

Using the method identified by `algorithm`, this method attempts to generate a digest of `data`. If successful, the returned promise is resolved with an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> containing the computed digest.

If `algorithm` is provided as a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>, it must be one of:

- `'cSHAKE128'`[^modern-algos]
- `'cSHAKE256'`[^modern-algos]
- `'SHA-1'`
- `'SHA-256'`
- `'SHA-384'`
- `'SHA-512'`
- `'SHA3-256'`[^modern-algos]
- `'SHA3-384'`[^modern-algos]
- `'SHA3-512'`[^modern-algos]

If `algorithm` is provided as an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a>, it must have a `name` property whose value is one of the above.

<hundefined>[object Object]</hundefined>
Added in: v24.7.0

> Stability: 1.1 - Active development

- `encapsulationAlgorithm` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>
- `encapsulationKey` <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with <a href="webcrypto.html#class-encapsulatedbits" class="type"><EncapsulatedBits></a> upon success.

Uses a message recipient's asymmetric public key to encrypt a temporary symmetric key. This encrypted key is the "encapsulated key" represented as <a href="webcrypto.html#class-encapsulatedbits" class="type"><EncapsulatedBits></a>.

The algorithms currently supported include:

- `'ML-KEM-512'`[^modern-algos]
- `'ML-KEM-768'`[^modern-algos]
- `'ML-KEM-1024'`[^modern-algos]

<hundefined>[object Object]</hundefined>
Added in: v24.7.0

> Stability: 1.1 - Active development

- `encapsulationAlgorithm` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>
- `encapsulationKey` <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>
- `sharedKeyAlgorithm` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a> | <a href="webcrypto.html#class-hmacimportparams" class="type"><HmacImportParams></a> | <a href="webcrypto.html#class-aesderivedkeyparams" class="type"><AesDerivedKeyParams></a> | <a href="webcrypto.html#class-kmacimportparams" class="type"><KmacImportParams></a>
- `extractable` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type" class="type"><boolean></a>
- `usages` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string[]></a> See Key usages.
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with <a href="webcrypto.html#class-encapsulatedkey" class="type"><EncapsulatedKey></a> upon success.

Uses a message recipient's asymmetric public key to encrypt a temporary symmetric key. This encrypted key is the "encapsulated key" represented as <a href="webcrypto.html#class-encapsulatedkey" class="type"><EncapsulatedKey></a>.

The algorithms currently supported include:

- `'ML-KEM-512'`[^modern-algos]
- `'ML-KEM-768'`[^modern-algos]
- `'ML-KEM-1024'`[^modern-algos]

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.7.0 | AES-OCB algorithm is now supported.
v24.7.0 | ChaCha20-Poly1305 algorithm is now supported.
v15.0.0 | Added in: v15.0.0

- `algorithm` <a href="webcrypto.html#class-rsaoaepparams" class="type"><RsaOaepParams></a> | <a href="webcrypto.html#class-aesctrparams" class="type"><AesCtrParams></a> | <a href="webcrypto.html#class-aescbcparams" class="type"><AesCbcParams></a> | <a href="webcrypto.html#class-aeadparams" class="type"><AeadParams></a>
- `key` <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>
- `data` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> upon success.

Using the method and parameters specified by `algorithm` and the keying material provided by `key`, this method attempts to encipher `data`. If successful, the returned promise is resolved with an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> containing the encrypted result.

The algorithms currently supported include:

- `'AES-CBC'`
- `'AES-CTR'`
- `'AES-GCM'`
- `'AES-OCB'`[^modern-algos]
- `'ChaCha20-Poly1305'`[^modern-algos]
- `'RSA-OAEP'`

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.8.0 | KMAC algorithms are now supported.
v24.7.0 | ML-KEM algorithms are now supported.
v24.7.0 | ChaCha20-Poly1305 algorithm is now supported.
v24.7.0 | ML-DSA algorithms are now supported.
v18.4.0, v16.17.0 | Added `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'` algorithms.
v15.9.0 | Removed `'NODE-DSA'` JWK export.
v15.0.0 | Added in: v15.0.0

- `format` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be one of `'raw'`, `'pkcs8'`, `'spki'`, `'jwk'`, `'raw-secret'`[^modern-algos], `'raw-public'`[^modern-algos], or `'raw-seed'`[^modern-algos].
- `key` <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> upon success.

Exports the given key into the specified format, if supported.

If the <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> is not extractable, the returned promise will reject.

When `format` is either `'pkcs8'` or `'spki'` and the export is successful, the returned promise will be resolved with an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> containing the exported key data.

When `format` is `'jwk'` and the export is successful, the returned promise will be resolved with a JavaScript object conforming to the JSON Web Key specification.

Supported Key Algorithm | `'spki'` | `'pkcs8'` | `'jwk'` | `'raw'` | `'raw-secret'` | `'raw-public'` | `'raw-seed'`
--- | --- | --- | --- | --- | --- | --- | ---
`'AES-CBC'` |  |  | ✔ | ✔ | ✔ |  |
`'AES-CTR'` |  |  | ✔ | ✔ | ✔ |  |
`'AES-GCM'` |  |  | ✔ | ✔ | ✔ |  |
`'AES-KW'` |  |  | ✔ | ✔ | ✔ |  |
`'AES-OCB'`[^modern-algos] |  |  | ✔ |  | ✔ |  |
`'ChaCha20-Poly1305'`[^modern-algos] |  |  | ✔ |  | ✔ |  |
`'ECDH'` | ✔ | ✔ | ✔ | ✔ |  | ✔ |
`'ECDSA'` | ✔ | ✔ | ✔ | ✔ |  | ✔ |
`'Ed25519'` | ✔ | ✔ | ✔ | ✔ |  | ✔ |
`'Ed448'`[^secure-curves] | ✔ | ✔ | ✔ | ✔ |  | ✔ |
`'HMAC'` |  |  | ✔ | ✔ | ✔ |  |
`'KMAC128'`[^modern-algos] |  |  | ✔ |  | ✔ |  |
`'KMAC256'`[^modern-algos] |  |  | ✔ |  | ✔ |  |
`'ML-DSA-44'`[^modern-algos] | ✔ | ✔ | ✔ |  |  | ✔ | ✔
`'ML-DSA-65'`[^modern-algos] | ✔ | ✔ | ✔ |  |  | ✔ | ✔
`'ML-DSA-87'`[^modern-algos] | ✔ | ✔ | ✔ |  |  | ✔ | ✔
`'ML-KEM-512'`[^modern-algos] | ✔ | ✔ |  |  |  | ✔ | ✔
`'ML-KEM-768'`[^modern-algos] | ✔ | ✔ |  |  |  | ✔ | ✔
`'ML-KEM-1024'`[^modern-algos] | ✔ | ✔ |  |  |  | ✔ | ✔
`'RSA-OAEP'` | ✔ | ✔ | ✔ |  |  |  |
`'RSA-PSS'` | ✔ | ✔ | ✔ |  |  |  |
`'RSASSA-PKCS1-v1_5'` | ✔ | ✔ | ✔ |  |  |  |

<hundefined>[object Object]</hundefined>
Added in: v24.7.0

> Stability: 1.1 - Active development

- `key` <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> A private key from which to derive the corresponding public key.
- `keyUsages` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string[]></a> See Key usages.
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with a <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> upon success.

Derives the public key from a given private key.

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.8.0 | KMAC algorithms are now supported.
v24.7.0 | ML-KEM algorithms are now supported.
v24.7.0 | ChaCha20-Poly1305 algorithm is now supported.
v24.7.0 | ML-DSA algorithms are now supported.
v15.0.0 | Added in: v15.0.0

- `algorithm` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a> | <a href="webcrypto.html#class-rsahashedkeygenparams" class="type"><RsaHashedKeyGenParams></a> | <a href="webcrypto.html#class-eckeygenparams" class="type"><EcKeyGenParams></a> | <a href="webcrypto.html#class-hmackeygenparams" class="type"><HmacKeyGenParams></a> | <a href="webcrypto.html#class-aeskeygenparams" class="type"><AesKeyGenParams></a> | <a href="webcrypto.html#class-kmackeygenparams" class="type"><KmacKeyGenParams></a>

- `extractable` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type" class="type"><boolean></a>
- `keyUsages` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string[]></a> See Key usages.
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with a <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> | <a href="webcrypto.html#class-cryptokeypair" class="type"><CryptoKeyPair></a> upon success.

Using the parameters provided in `algorithm`, this method attempts to generate new keying material. Depending on the algorithm used either a single <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> or a <a href="webcrypto.html#class-cryptokeypair" class="type"><CryptoKeyPair></a> is generated.

The <a href="webcrypto.html#class-cryptokeypair" class="type"><CryptoKeyPair></a> (public and private key) generating algorithms supported include:

- `'ECDH'`
- `'ECDSA'`
- `'Ed25519'`
- `'Ed448'`[^secure-curves]
- `'ML-DSA-44'`[^modern-algos]
- `'ML-DSA-65'`[^modern-algos]
- `'ML-DSA-87'`[^modern-algos]
- `'ML-KEM-512'`[^modern-algos]
- `'ML-KEM-768'`[^modern-algos]
- `'ML-KEM-1024'`[^modern-algos]
- `'RSA-OAEP'`
- `'RSA-PSS'`
- `'RSASSA-PKCS1-v1_5'`
- `'X25519'`
- `'X448'`[^secure-curves]

The <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> (secret key) generating algorithms supported include:

- `'AES-CBC'`
- `'AES-CTR'`
- `'AES-GCM'`
- `'AES-KW'`
- `'AES-OCB'`[^modern-algos]
- `'ChaCha20-Poly1305'`[^modern-algos]
- `'HMAC'`
- `'KMAC128'`[^modern-algos]
- `'KMAC256'`[^modern-algos]

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.15.0 | Importing ML-DSA and ML-KEM PKCS#8 keys without a seed is no longer supported.
v24.8.0 | KMAC algorithms are now supported.
v24.7.0 | ML-KEM algorithms are now supported.
v24.7.0 | ChaCha20-Poly1305 algorithm is now supported.
v24.7.0 | ML-DSA algorithms are now supported.
v18.4.0, v16.17.0 | Added `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'` algorithms.
v15.9.0 | Removed `'NODE-DSA'` JWK import.
v15.0.0 | Added in: v15.0.0

- `format` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be one of `'raw'`, `'pkcs8'`, `'spki'`, `'jwk'`, `'raw-secret'`[^modern-algos], `'raw-public'`[^modern-algos], or `'raw-seed'`[^modern-algos].
- `keyData` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a>

- `algorithm` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a> | <a href="webcrypto.html#class-rsahashedimportparams" class="type"><RsaHashedImportParams></a> | <a href="webcrypto.html#class-eckeyimportparams" class="type"><EcKeyImportParams></a> | <a href="webcrypto.html#class-hmacimportparams" class="type"><HmacImportParams></a> | <a href="webcrypto.html#class-kmacimportparams" class="type"><KmacImportParams></a>

- `extractable` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type" class="type"><boolean></a>
- `keyUsages` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string[]></a> See Key usages.
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with a <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> upon success.

This method attempts to interpret the provided `keyData` as the given `format` to create a <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> instance using the provided `algorithm`, `extractable`, and `keyUsages` arguments. If the import is successful, the returned promise will be resolved with a <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> representation of the key material.

If importing KDF algorithm keys, `extractable` must be `false`.

The algorithms currently supported include:

Supported Key Algorithm | `'spki'` | `'pkcs8'` | `'jwk'` | `'raw'` | `'raw-secret'` | `'raw-public'` | `'raw-seed'`
--- | --- | --- | --- | --- | --- | --- | ---
`'AES-CBC'` |  |  | ✔ | ✔ | ✔ |  |
`'AES-CTR'` |  |  | ✔ | ✔ | ✔ |  |
`'AES-GCM'` |  |  | ✔ | ✔ | ✔ |  |
`'AES-KW'` |  |  | ✔ | ✔ | ✔ |  |
`'AES-OCB'`[^modern-algos] |  |  | ✔ |  | ✔ |  |
`'Argon2d'`[^modern-algos] |  |  |  |  | ✔ |  |
`'Argon2i'`[^modern-algos] |  |  |  |  | ✔ |  |
`'Argon2id'`[^modern-algos] |  |  |  |  | ✔ |  |
`'ChaCha20-Poly1305'`[^modern-algos] |  |  | ✔ |  | ✔ |  |
`'ECDH'` | ✔ | ✔ | ✔ | ✔ |  | ✔ |
`'ECDSA'` | ✔ | ✔ | ✔ | ✔ |  | ✔ |
`'Ed25519'` | ✔ | ✔ | ✔ | ✔ |  | ✔ |
`'Ed448'`[^secure-curves] | ✔ | ✔ | ✔ | ✔ |  | ✔ |
`'HKDF'` |  |  |  | ✔ | ✔ |  |
`'HMAC'` |  |  | ✔ | ✔ | ✔ |  |
`'KMAC128'`[^modern-algos] |  |  | ✔ |  | ✔ |  |
`'KMAC256'`[^modern-algos] |  |  | ✔ |  | ✔ |  |
`'ML-DSA-44'`[^modern-algos] | ✔ | ✔ | ✔ |  |  | ✔ | ✔
`'ML-DSA-65'`[^modern-algos] | ✔ | ✔ | ✔ |  |  | ✔ | ✔
`'ML-DSA-87'`[^modern-algos] | ✔ | ✔ | ✔ |  |  | ✔ | ✔
`'ML-KEM-512'`[^modern-algos] | ✔ | ✔ |  |  |  | ✔ | ✔
`'ML-KEM-768'`[^modern-algos] | ✔ | ✔ |  |  |  | ✔ | ✔
`'ML-KEM-1024'`[^modern-algos] | ✔ | ✔ |  |  |  | ✔ | ✔
`'PBKDF2'` |  |  |  | ✔ | ✔ |  |
`'RSA-OAEP'` | ✔ | ✔ | ✔ |  |  |  |
`'RSA-PSS'` | ✔ | ✔ | ✔ |  |  |  |
`'RSASSA-PKCS1-v1_5'` | ✔ | ✔ | ✔ |  |  |  |
`'X25519'` | ✔ | ✔ | ✔ | ✔ |  | ✔ |
`'X448'`[^secure-curves] | ✔ | ✔ | ✔ | ✔ |  | ✔ |

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.8.0 | KMAC algorithms are now supported.
v24.7.0 | ML-DSA algorithms are now supported.
v18.4.0, v16.17.0 | Added `'Ed25519'`, and `'Ed448'` algorithms.
v15.0.0 | Added in: v15.0.0

- `algorithm` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a> | <a href="webcrypto.html#class-rsapssparams" class="type"><RsaPssParams></a> | <a href="webcrypto.html#class-ecdsaparams" class="type"><EcdsaParams></a> | <a href="webcrypto.html#class-contextparams" class="type"><ContextParams></a> | <a href="webcrypto.html#class-kmacparams" class="type"><KmacParams></a>
- `key` <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>
- `data` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> upon success.

Using the method and parameters given by `algorithm` and the keying material provided by `key`, this method attempts to generate a cryptographic signature of `data`. If successful, the returned promise is resolved with an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> containing the generated signature.

The algorithms currently supported include:

- `'ECDSA'`
- `'Ed25519'`
- `'Ed448'`[^secure-curves]
- `'HMAC'`
- `'KMAC128'`[^modern-algos]
- `'KMAC256'`[^modern-algos]
- `'ML-DSA-44'`[^modern-algos]
- `'ML-DSA-65'`[^modern-algos]
- `'ML-DSA-87'`[^modern-algos]
- `'RSA-PSS'`
- `'RSASSA-PKCS1-v1_5'`

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.7.0 | AES-OCB algorithm is now supported.
v24.7.0 | ChaCha20-Poly1305 algorithm is now supported.
v15.0.0 | Added in: v15.0.0

- `format` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be one of `'raw'`, `'pkcs8'`, `'spki'`, `'jwk'`, `'raw-secret'`[^modern-algos], `'raw-public'`[^modern-algos], or `'raw-seed'`[^modern-algos].
- `wrappedKey` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>
- `unwrappingKey` <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>

- `unwrapAlgo` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a> | <a href="webcrypto.html#class-rsaoaepparams" class="type"><RsaOaepParams></a> | <a href="webcrypto.html#class-aesctrparams" class="type"><AesCtrParams></a> | <a href="webcrypto.html#class-aescbcparams" class="type"><AesCbcParams></a> | <a href="webcrypto.html#class-aeadparams" class="type"><AeadParams></a>
- `unwrappedKeyAlgo` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a> | <a href="webcrypto.html#class-rsahashedimportparams" class="type"><RsaHashedImportParams></a> | <a href="webcrypto.html#class-eckeyimportparams" class="type"><EcKeyImportParams></a> | <a href="webcrypto.html#class-hmacimportparams" class="type"><HmacImportParams></a> | <a href="webcrypto.html#class-kmacimportparams" class="type"><KmacImportParams></a>

- `extractable` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type" class="type"><boolean></a>
- `keyUsages` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string[]></a> See Key usages.
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with a <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> upon success.

In cryptography, "wrapping a key" refers to exporting and then encrypting the keying material. This method attempts to decrypt a wrapped key and create a <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> instance. It is equivalent to calling `subtle.decrypt()` first on the encrypted key data (using the `wrappedKey`, `unwrapAlgo`, and `unwrappingKey` arguments as input) then passing the results to the `subtle.importKey()` method using the `unwrappedKeyAlgo`, `extractable`, and `keyUsages` arguments as inputs. If successful, the returned promise is resolved with a <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a> object.

The wrapping algorithms currently supported include:

- `'AES-CBC'`
- `'AES-CTR'`
- `'AES-GCM'`
- `'AES-KW'`
- `'AES-OCB'`[^modern-algos]
- `'ChaCha20-Poly1305'`[^modern-algos]
- `'RSA-OAEP'`

The unwrapped key algorithms supported include:

- `'AES-CBC'`
- `'AES-CTR'`
- `'AES-GCM'`
- `'AES-KW'`
- `'AES-OCB'`[^modern-algos]
- `'ChaCha20-Poly1305'`[^modern-algos]
- `'ECDH'`
- `'ECDSA'`
- `'Ed25519'`
- `'Ed448'`[^secure-curves]
- `'HMAC'`
- `'KMAC128'`[^modern-algos]
- `'KMAC256'`[^modern-algos]
- `'ML-DSA-44'`[^modern-algos]
- `'ML-DSA-65'`[^modern-algos]
- `'ML-DSA-87'`[^modern-algos]
- `'ML-KEM-512'`[^modern-algos]
- `'ML-KEM-768'`[^modern-algos]
- `'ML-KEM-1024'`[^modern-algos]
- `'RSA-OAEP'`
- `'RSA-PSS'`
- `'RSASSA-PKCS1-v1_5'`
- `'X25519'`
- `'X448'`[^secure-curves]

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.8.0 | KMAC algorithms are now supported.
v24.7.0 | ML-DSA algorithms are now supported.
v18.4.0, v16.17.0 | Added `'Ed25519'`, and `'Ed448'` algorithms.
v15.0.0 | Added in: v15.0.0

- `algorithm` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a> | <a href="webcrypto.html#class-rsapssparams" class="type"><RsaPssParams></a> | <a href="webcrypto.html#class-ecdsaparams" class="type"><EcdsaParams></a> | <a href="webcrypto.html#class-contextparams" class="type"><ContextParams></a> | <a href="webcrypto.html#class-kmacparams" class="type"><KmacParams></a>
- `key` <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>
- `signature` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>
- `data` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type" class="type"><boolean></a> upon success.

Using the method and parameters given in `algorithm` and the keying material provided by `key`, this method attempts to verify that `signature` is a valid cryptographic signature of `data`. The returned promise is resolved with either `true` or `false`.

The algorithms currently supported include:

- `'ECDSA'`
- `'Ed25519'`
- `'Ed448'`[^secure-curves]
- `'HMAC'`
- `'KMAC128'`[^modern-algos]
- `'KMAC256'`[^modern-algos]
- `'ML-DSA-44'`[^modern-algos]
- `'ML-DSA-65'`[^modern-algos]
- `'ML-DSA-87'`[^modern-algos]
- `'RSA-PSS'`
- `'RSASSA-PKCS1-v1_5'`

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.7.0 | AES-OCB algorithm is now supported.
v24.7.0 | ChaCha20-Poly1305 algorithm is now supported.
v15.0.0 | Added in: v15.0.0

- `format` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be one of `'raw'`, `'pkcs8'`, `'spki'`, `'jwk'`, `'raw-secret'`[^modern-algos], `'raw-public'`[^modern-algos], or `'raw-seed'`[^modern-algos].
- `key` <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>
- `wrappingKey` <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>
- `wrapAlgo` <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a> | <a href="webcrypto.html#class-rsaoaepparams" class="type"><RsaOaepParams></a> | <a href="webcrypto.html#class-aesctrparams" class="type"><AesCtrParams></a> | <a href="webcrypto.html#class-aescbcparams" class="type"><AesCbcParams></a> | <a href="webcrypto.html#class-aeadparams" class="type"><AeadParams></a>
- Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> Fulfills with an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> upon success.

In cryptography, "wrapping a key" refers to exporting and then encrypting the keying material. This 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 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> containing the encrypted key data.

The wrapping algorithms currently supported include:

- `'AES-CBC'`
- `'AES-CTR'`
- `'AES-GCM'`
- `'AES-KW'`
- `'AES-OCB'`[^modern-algos]
- `'ChaCha20-Poly1305'`[^modern-algos]
- `'RSA-OAEP'`

<hundefined>[object Object]</hundefined>

The algorithm parameter objects define the methods and parameters used by the various <a href="webcrypto.html#class-subtlecrypto" class="type"><SubtleCrypto></a> methods. While described here as "classes", they are simple JavaScript dictionary objects.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type" class="type"><undefined></a>

Extra input that is not encrypted but is included in the authentication of the data. The use of `additionalData` is optional.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>

The initialization vector must be unique for every encryption operation using a given key.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be `'AES-GCM'`, `'AES-OCB'`, or `'ChaCha20-Poly1305'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a> The size in bits of the generated authentication tag.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be one of `'AES-CBC'`, `'AES-CTR'`, `'AES-GCM'`, `'AES-OCB'`, or `'AES-KW'`

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

The length of the AES key to be derived. This must be either `128`, `192`, or `256`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>

Provides the initialization vector. It must be exactly 16-bytes in length and should be unpredictable and cryptographically random.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be `'AES-CBC'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>

The initial value of the counter block. This must be exactly 16 bytes long.

The `AES-CTR` method uses the rightmost `length` bits of the block as the counter and the remaining bits as the nonce.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a> The number of bits in the `aesCtrParams.counter` that are to be used as the counter.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be `'AES-CTR'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

The length of the AES key in bits.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

The length of the AES key to be generated. This must be either `128`, `192`, or `256`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be one of `'AES-CBC'`, `'AES-CTR'`, `'AES-GCM'`, or `'AES-KW'`

<hundefined>[object Object]</hundefined>
Added in: v24.8.0
<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>

Represents the optional associated data.

<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

Represents the memory size in kibibytes. It must be at least 8 times the degree of parallelism.

<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be one of `'Argon2d'`, `'Argon2i'`, or `'Argon2id'`.

<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>

Represents the nonce, which is a salt for password hashing applications.

<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

Represents the degree of parallelism.

<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

Represents the number of passes.

<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>

Represents the optional secret value.

<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

Represents the Argon2 version number. The default and currently only defined version is `19` (`0x13`).

<hundefined>[object Object]</hundefined>
Added in: v24.7.0
<hundefined>[object Object]</hundefined>
Added in: v24.7.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be `'Ed448'`[^secure-curves], `'ML-DSA-44'`[^modern-algos], `'ML-DSA-65'`[^modern-algos], or `'ML-DSA-87'`[^modern-algos].

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.8.0 | Non-empty context is now supported.
v24.7.0 | Added in: v24.7.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type" class="type"><undefined></a>

The `context` member represents the optional context data to associate with the message.

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.15.0 | Renamed `cShakeParams.length` to `cShakeParams.outputLength`.
v24.7.0 | Added in: v24.7.0

<hundefined>[object Object]</hundefined>
Added in: v24.7.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be `'cSHAKE128'`[^modern-algos] or `'cSHAKE256'`[^modern-algos].

<hundefined>[object Object]</hundefined>
Added in: v24.15.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a> represents the requested output length in bits.

<hundefined>[object Object]</hundefined>
Added in: v24.7.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type" class="type"><undefined></a>

The `functionName` member represents the function name, used by NIST to define functions based on cSHAKE. The Node.js Web Crypto API implementation only supports zero-length functionName which is equivalent to not providing functionName at all.

<hundefined>[object Object]</hundefined>
Added in: v24.7.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type" class="type"><undefined></a>

The `customization` member represents the customization string. The Node.js Web Crypto API implementation only supports zero-length customization which is equivalent to not providing customization at all.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be `'ECDH'`, `'X25519'`, or `'X448'`[^secure-curves].

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>

ECDH key derivation operates by taking as input one party's private key and another party's public key -- using both to generate a common shared secret. The `ecdhKeyDeriveParams.public` property is set to the other party's public key.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.7.0 | SHA-3 algorithms are now supported.
v15.0.0 | Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>

If represented as a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>, the value must be one of:

- `'SHA-1'`
- `'SHA-256'`
- `'SHA-384'`
- `'SHA-512'`
- `'SHA3-256'`[^modern-algos]
- `'SHA3-384'`[^modern-algos]
- `'SHA3-512'`[^modern-algos]

If represented as an <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>, the object's `name` property must be one of the above listed values.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be `'ECDSA'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be one of `'ECDSA'` or `'ECDH'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be one of `'P-256'`, `'P-384'`, `'P-521'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be one of `'ECDSA'` or `'ECDH'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be one of `'P-256'`, `'P-384'`, `'P-521'`.

<hundefined>[object Object]</hundefined>
Added in: v24.7.0

A temporary symmetric secret key (represented as <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a>) for message encryption and the ciphertext (that can be transmitted to the message recipient along with the message) encrypted by this shared key. The recipient uses their private key to determine what the shared key is which then allows them to decrypt the message.

<hundefined>[object Object]</hundefined>
Added in: v24.7.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a>

<hundefined>[object Object]</hundefined>
Added in: v24.7.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a>

<hundefined>[object Object]</hundefined>
Added in: v24.7.0

A temporary symmetric secret key (represented as <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>) for message encryption and the ciphertext (that can be transmitted to the message recipient along with the message) encrypted by this shared key. The recipient uses their private key to determine what the shared key is which then allows them to decrypt the message.

<hundefined>[object Object]</hundefined>
Added in: v24.7.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a>

<hundefined>[object Object]</hundefined>
Added in: v24.7.0

- Type: <a href="webcrypto.html#class-cryptokey" class="type"><CryptoKey></a>

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.7.0 | SHA-3 algorithms are now supported.
v15.0.0 | Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>

If represented as a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>, the value must be one of:

- `'SHA-1'`
- `'SHA-256'`
- `'SHA-384'`
- `'SHA-512'`
- `'SHA3-256'`[^modern-algos]
- `'SHA3-384'`[^modern-algos]
- `'SHA3-512'`[^modern-algos]

If represented as an <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>, the object's `name` property must be one of the above listed values.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>

Provides application-specific contextual input to the HKDF algorithm. This can be zero-length but must be provided.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be `'HKDF'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>

The salt value significantly improves the strength of the HKDF algorithm. It should be random or pseudorandom and should be the same length as the output of the digest function (for instance, if using `'SHA-256'` as the digest, the salt should be 256-bits of random data).

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.7.0 | SHA-3 algorithms are now supported.
v15.0.0 | Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>

If represented as a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>, the value must be one of:

- `'SHA-1'`
- `'SHA-256'`
- `'SHA-384'`
- `'SHA-512'`
- `'SHA3-256'`[^modern-algos]
- `'SHA3-384'`[^modern-algos]
- `'SHA3-512'`[^modern-algos]

If represented as an <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>, the object's `name` property must be one of the above listed values.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

The optional number of bits in the HMAC key. This is optional and should be omitted for most cases.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be `'HMAC'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

The length of the HMAC key in bits.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.7.0 | SHA-3 algorithms are now supported.
v15.0.0 | Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>

If represented as a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>, the value must be one of:

- `'SHA-1'`
- `'SHA-256'`
- `'SHA-384'`
- `'SHA-512'`
- `'SHA3-256'`[^modern-algos]
- `'SHA3-384'`[^modern-algos]
- `'SHA3-512'`[^modern-algos]

If represented as an <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>, the object's `name` property must be one of the above listed values.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

The number of bits to generate for the HMAC key. If omitted, the length will be determined by the hash algorithm used. This is optional and should be omitted for most cases.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be `'HMAC'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>

<hundefined>[object Object]</hundefined>
Added in: v24.8.0
<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

The optional number of bits in the KMAC key. This is optional and should be omitted for most cases.

<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be `'KMAC128'` or `'KMAC256'`.

<hundefined>[object Object]</hundefined>
Added in: v24.8.0
<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

The length of the KMAC key in bits.

<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>

<hundefined>[object Object]</hundefined>
Added in: v24.8.0
<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

The number of bits to generate for the KMAC key. If omitted, the length will be determined by the KMAC algorithm used. This is optional and should be omitted for most cases.

<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be `'KMAC128'` or `'KMAC256'`.

<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.15.0 | Renamed `kmacParams.length` to `kmacParams.outputLength`.
v24.8.0 | Added in: v24.8.0

<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be `'KMAC128'` or `'KMAC256'`.

<hundefined>[object Object]</hundefined>
Added in: v24.15.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

The length of the output in bytes. This must be a positive integer.

<hundefined>[object Object]</hundefined>
Added in: v24.8.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type" class="type"><undefined></a>

The `customization` member represents the optional customization string.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.7.0 | SHA-3 algorithms are now supported.
v15.0.0 | Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>

If represented as a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>, the value must be one of:

- `'SHA-1'`
- `'SHA-256'`
- `'SHA-384'`
- `'SHA-512'`
- `'SHA3-256'`[^modern-algos]
- `'SHA3-384'`[^modern-algos]
- `'SHA3-512'`[^modern-algos]

If represented as an <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>, the object's `name` property must be one of the above listed values.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

The number of iterations the PBKDF2 algorithm should make when deriving bits.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be `'PBKDF2'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>

Should be at least 16 random or pseudorandom bytes.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.7.0 | SHA-3 algorithms are now supported.
v15.0.0 | Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>

If represented as a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>, the value must be one of:

- `'SHA-1'`
- `'SHA-256'`
- `'SHA-384'`
- `'SHA-512'`
- `'SHA3-256'`[^modern-algos]
- `'SHA3-384'`[^modern-algos]
- `'SHA3-512'`[^modern-algos]

If represented as an <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>, the object's `name` property must be one of the above listed values.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be one of `'RSASSA-PKCS1-v1_5'`, `'RSA-PSS'`, or `'RSA-OAEP'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

The length in bits of the RSA modulus.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type"><Uint8Array></a>

The RSA public exponent.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
History

Version | Changes
--- | ---
v24.7.0 | SHA-3 algorithms are now supported.
v15.0.0 | Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> | <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>

If represented as a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a>, the value must be one of:

- `'SHA-1'`
- `'SHA-256'`
- `'SHA-384'`
- `'SHA-512'`
- `'SHA3-256'`[^modern-algos]
- `'SHA3-384'`[^modern-algos]
- `'SHA3-512'`[^modern-algos]

If represented as an <a href="webcrypto.html#class-algorithm" class="type"><Algorithm></a>, the object's `name` property must be one of the above listed values.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

The length in bits of the RSA modulus. As a best practice, this should be at least `2048`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be one of `'RSASSA-PKCS1-v1_5'`, `'RSA-PSS'`, or `'RSA-OAEP'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type"><Uint8Array></a>

The RSA public exponent. This must be a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type"><Uint8Array></a> containing a big-endian, unsigned integer that must fit within 32-bits. The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type"><Uint8Array></a> may contain an arbitrary number of leading zero-bits. The value must be a prime number. Unless there is reason to use a different value, use `new Uint8Array([1, 0, 1])` (65537) as the public exponent.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type"><ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type"><TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type"><DataView></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a>

An additional collection of bytes that will not be encrypted, but will be bound to the generated ciphertext.

The `rsaOaepParams.label` parameter is optional.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> must be `'RSA-OAEP'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0
<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type" class="type"><string></a> Must be `'RSA-PSS'`.

<hundefined>[object Object]</hundefined>
Added in: v15.0.0

- Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" class="type"><number></a>

The length (in bytes) of the random salt to use.

[^secure-curves]: See Secure Curves in the Web Cryptography API

[^modern-algos]: See Modern Algorithms in the Web Cryptography API

[^openssl30]: Requires OpenSSL >= 3.0

[^openssl32]: Requires OpenSSL >= 3.2

[^openssl35]: Requires OpenSSL >= 3.5