11cb0ef41Sopenharmony_ci# Web Crypto API
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci<!-- YAML
41cb0ef41Sopenharmony_cichanges:
51cb0ef41Sopenharmony_ci  - version: v18.17.0
61cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/46067
71cb0ef41Sopenharmony_ci    description: Arguments are now coerced and validated as per their WebIDL
81cb0ef41Sopenharmony_ci      definitions like in other Web Crypto API implementations.
91cb0ef41Sopenharmony_ci  - version: v18.4.0
101cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/43310
111cb0ef41Sopenharmony_ci    description: Removed proprietary `'node.keyObject'` import/export format.
121cb0ef41Sopenharmony_ci  - version: v18.4.0
131cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/43310
141cb0ef41Sopenharmony_ci    description: Removed proprietary `'NODE-DSA'`, `'NODE-DH'`,
151cb0ef41Sopenharmony_ci      and `'NODE-SCRYPT'` algorithms.
161cb0ef41Sopenharmony_ci  - version: v18.4.0
171cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/42507
181cb0ef41Sopenharmony_ci    description: Added `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'`
191cb0ef41Sopenharmony_ci      algorithms.
201cb0ef41Sopenharmony_ci  - version: v18.4.0
211cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/42507
221cb0ef41Sopenharmony_ci    description: Removed proprietary `'NODE-ED25519'` and `'NODE-ED448'`
231cb0ef41Sopenharmony_ci      algorithms.
241cb0ef41Sopenharmony_ci  - version: v18.4.0
251cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/42507
261cb0ef41Sopenharmony_ci    description: Removed proprietary `'NODE-X25519'` and `'NODE-X448'` named
271cb0ef41Sopenharmony_ci      curves from the `'ECDH'` algorithm.
281cb0ef41Sopenharmony_ci-->
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci<!-- introduced_in=v15.0.0 -->
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci> Stability: 1 - Experimental
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ciNode.js provides an implementation of the standard [Web Crypto API][].
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ciUse `require('node:crypto').webcrypto` to access this module.
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci```js
391cb0ef41Sopenharmony_ciconst { subtle } = require('node:crypto').webcrypto;
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci(async function() {
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci  const key = await subtle.generateKey({
441cb0ef41Sopenharmony_ci    name: 'HMAC',
451cb0ef41Sopenharmony_ci    hash: 'SHA-256',
461cb0ef41Sopenharmony_ci    length: 256,
471cb0ef41Sopenharmony_ci  }, true, ['sign', 'verify']);
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci  const enc = new TextEncoder();
501cb0ef41Sopenharmony_ci  const message = enc.encode('I love cupcakes');
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci  const digest = await subtle.sign({
531cb0ef41Sopenharmony_ci    name: 'HMAC',
541cb0ef41Sopenharmony_ci  }, key, message);
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci})();
571cb0ef41Sopenharmony_ci```
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci## Examples
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci### Generating keys
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ciThe {SubtleCrypto} class can be used to generate symmetric (secret) keys
641cb0ef41Sopenharmony_cior asymmetric key pairs (public key and private key).
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci#### AES keys
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ci```js
691cb0ef41Sopenharmony_ciconst { subtle } = require('node:crypto').webcrypto;
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ciasync function generateAesKey(length = 256) {
721cb0ef41Sopenharmony_ci  const key = await subtle.generateKey({
731cb0ef41Sopenharmony_ci    name: 'AES-CBC',
741cb0ef41Sopenharmony_ci    length,
751cb0ef41Sopenharmony_ci  }, true, ['encrypt', 'decrypt']);
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ci  return key;
781cb0ef41Sopenharmony_ci}
791cb0ef41Sopenharmony_ci```
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ci#### ECDSA key pairs
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci```js
841cb0ef41Sopenharmony_ciconst { subtle } = require('node:crypto').webcrypto;
851cb0ef41Sopenharmony_ci
861cb0ef41Sopenharmony_ciasync function generateEcKey(namedCurve = 'P-521') {
871cb0ef41Sopenharmony_ci  const {
881cb0ef41Sopenharmony_ci    publicKey,
891cb0ef41Sopenharmony_ci    privateKey,
901cb0ef41Sopenharmony_ci  } = await subtle.generateKey({
911cb0ef41Sopenharmony_ci    name: 'ECDSA',
921cb0ef41Sopenharmony_ci    namedCurve,
931cb0ef41Sopenharmony_ci  }, true, ['sign', 'verify']);
941cb0ef41Sopenharmony_ci
951cb0ef41Sopenharmony_ci  return { publicKey, privateKey };
961cb0ef41Sopenharmony_ci}
971cb0ef41Sopenharmony_ci```
981cb0ef41Sopenharmony_ci
991cb0ef41Sopenharmony_ci#### Ed25519/Ed448/X25519/X448 key pairs
1001cb0ef41Sopenharmony_ci
1011cb0ef41Sopenharmony_ci> Stability: 1 - Experimental
1021cb0ef41Sopenharmony_ci
1031cb0ef41Sopenharmony_ci```js
1041cb0ef41Sopenharmony_ciconst { subtle } = require('node:crypto').webcrypto;
1051cb0ef41Sopenharmony_ci
1061cb0ef41Sopenharmony_ciasync function generateEd25519Key() {
1071cb0ef41Sopenharmony_ci  return subtle.generateKey({
1081cb0ef41Sopenharmony_ci    name: 'Ed25519',
1091cb0ef41Sopenharmony_ci  }, true, ['sign', 'verify']);
1101cb0ef41Sopenharmony_ci}
1111cb0ef41Sopenharmony_ci
1121cb0ef41Sopenharmony_ciasync function generateX25519Key() {
1131cb0ef41Sopenharmony_ci  return subtle.generateKey({
1141cb0ef41Sopenharmony_ci    name: 'X25519',
1151cb0ef41Sopenharmony_ci  }, true, ['deriveKey']);
1161cb0ef41Sopenharmony_ci}
1171cb0ef41Sopenharmony_ci```
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_ci#### HMAC keys
1201cb0ef41Sopenharmony_ci
1211cb0ef41Sopenharmony_ci```js
1221cb0ef41Sopenharmony_ciconst { subtle } = require('node:crypto').webcrypto;
1231cb0ef41Sopenharmony_ci
1241cb0ef41Sopenharmony_ciasync function generateHmacKey(hash = 'SHA-256') {
1251cb0ef41Sopenharmony_ci  const key = await subtle.generateKey({
1261cb0ef41Sopenharmony_ci    name: 'HMAC',
1271cb0ef41Sopenharmony_ci    hash,
1281cb0ef41Sopenharmony_ci  }, true, ['sign', 'verify']);
1291cb0ef41Sopenharmony_ci
1301cb0ef41Sopenharmony_ci  return key;
1311cb0ef41Sopenharmony_ci}
1321cb0ef41Sopenharmony_ci```
1331cb0ef41Sopenharmony_ci
1341cb0ef41Sopenharmony_ci#### RSA key pairs
1351cb0ef41Sopenharmony_ci
1361cb0ef41Sopenharmony_ci```js
1371cb0ef41Sopenharmony_ciconst { subtle } = require('node:crypto').webcrypto;
1381cb0ef41Sopenharmony_ciconst publicExponent = new Uint8Array([1, 0, 1]);
1391cb0ef41Sopenharmony_ci
1401cb0ef41Sopenharmony_ciasync function generateRsaKey(modulusLength = 2048, hash = 'SHA-256') {
1411cb0ef41Sopenharmony_ci  const {
1421cb0ef41Sopenharmony_ci    publicKey,
1431cb0ef41Sopenharmony_ci    privateKey,
1441cb0ef41Sopenharmony_ci  } = await subtle.generateKey({
1451cb0ef41Sopenharmony_ci    name: 'RSASSA-PKCS1-v1_5',
1461cb0ef41Sopenharmony_ci    modulusLength,
1471cb0ef41Sopenharmony_ci    publicExponent,
1481cb0ef41Sopenharmony_ci    hash,
1491cb0ef41Sopenharmony_ci  }, true, ['sign', 'verify']);
1501cb0ef41Sopenharmony_ci
1511cb0ef41Sopenharmony_ci  return { publicKey, privateKey };
1521cb0ef41Sopenharmony_ci}
1531cb0ef41Sopenharmony_ci```
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ci### Encryption and decryption
1561cb0ef41Sopenharmony_ci
1571cb0ef41Sopenharmony_ci```js
1581cb0ef41Sopenharmony_ciconst crypto = require('node:crypto').webcrypto;
1591cb0ef41Sopenharmony_ci
1601cb0ef41Sopenharmony_ciasync function aesEncrypt(plaintext) {
1611cb0ef41Sopenharmony_ci  const ec = new TextEncoder();
1621cb0ef41Sopenharmony_ci  const key = await generateAesKey();
1631cb0ef41Sopenharmony_ci  const iv = crypto.getRandomValues(new Uint8Array(16));
1641cb0ef41Sopenharmony_ci
1651cb0ef41Sopenharmony_ci  const ciphertext = await crypto.subtle.encrypt({
1661cb0ef41Sopenharmony_ci    name: 'AES-CBC',
1671cb0ef41Sopenharmony_ci    iv,
1681cb0ef41Sopenharmony_ci  }, key, ec.encode(plaintext));
1691cb0ef41Sopenharmony_ci
1701cb0ef41Sopenharmony_ci  return {
1711cb0ef41Sopenharmony_ci    key,
1721cb0ef41Sopenharmony_ci    iv,
1731cb0ef41Sopenharmony_ci    ciphertext,
1741cb0ef41Sopenharmony_ci  };
1751cb0ef41Sopenharmony_ci}
1761cb0ef41Sopenharmony_ci
1771cb0ef41Sopenharmony_ciasync function aesDecrypt(ciphertext, key, iv) {
1781cb0ef41Sopenharmony_ci  const dec = new TextDecoder();
1791cb0ef41Sopenharmony_ci  const plaintext = await crypto.subtle.decrypt({
1801cb0ef41Sopenharmony_ci    name: 'AES-CBC',
1811cb0ef41Sopenharmony_ci    iv,
1821cb0ef41Sopenharmony_ci  }, key, ciphertext);
1831cb0ef41Sopenharmony_ci
1841cb0ef41Sopenharmony_ci  return dec.decode(plaintext);
1851cb0ef41Sopenharmony_ci}
1861cb0ef41Sopenharmony_ci```
1871cb0ef41Sopenharmony_ci
1881cb0ef41Sopenharmony_ci### Exporting and importing keys
1891cb0ef41Sopenharmony_ci
1901cb0ef41Sopenharmony_ci```js
1911cb0ef41Sopenharmony_ciconst { subtle } = require('node:crypto').webcrypto;
1921cb0ef41Sopenharmony_ci
1931cb0ef41Sopenharmony_ciasync function generateAndExportHmacKey(format = 'jwk', hash = 'SHA-512') {
1941cb0ef41Sopenharmony_ci  const key = await subtle.generateKey({
1951cb0ef41Sopenharmony_ci    name: 'HMAC',
1961cb0ef41Sopenharmony_ci    hash,
1971cb0ef41Sopenharmony_ci  }, true, ['sign', 'verify']);
1981cb0ef41Sopenharmony_ci
1991cb0ef41Sopenharmony_ci  return subtle.exportKey(format, key);
2001cb0ef41Sopenharmony_ci}
2011cb0ef41Sopenharmony_ci
2021cb0ef41Sopenharmony_ciasync function importHmacKey(keyData, format = 'jwk', hash = 'SHA-512') {
2031cb0ef41Sopenharmony_ci  const key = await subtle.importKey(format, keyData, {
2041cb0ef41Sopenharmony_ci    name: 'HMAC',
2051cb0ef41Sopenharmony_ci    hash,
2061cb0ef41Sopenharmony_ci  }, true, ['sign', 'verify']);
2071cb0ef41Sopenharmony_ci
2081cb0ef41Sopenharmony_ci  return key;
2091cb0ef41Sopenharmony_ci}
2101cb0ef41Sopenharmony_ci```
2111cb0ef41Sopenharmony_ci
2121cb0ef41Sopenharmony_ci### Wrapping and unwrapping keys
2131cb0ef41Sopenharmony_ci
2141cb0ef41Sopenharmony_ci```js
2151cb0ef41Sopenharmony_ciconst { subtle } = require('node:crypto').webcrypto;
2161cb0ef41Sopenharmony_ci
2171cb0ef41Sopenharmony_ciasync function generateAndWrapHmacKey(format = 'jwk', hash = 'SHA-512') {
2181cb0ef41Sopenharmony_ci  const [
2191cb0ef41Sopenharmony_ci    key,
2201cb0ef41Sopenharmony_ci    wrappingKey,
2211cb0ef41Sopenharmony_ci  ] = await Promise.all([
2221cb0ef41Sopenharmony_ci    subtle.generateKey({
2231cb0ef41Sopenharmony_ci      name: 'HMAC', hash,
2241cb0ef41Sopenharmony_ci    }, true, ['sign', 'verify']),
2251cb0ef41Sopenharmony_ci    subtle.generateKey({
2261cb0ef41Sopenharmony_ci      name: 'AES-KW',
2271cb0ef41Sopenharmony_ci      length: 256,
2281cb0ef41Sopenharmony_ci    }, true, ['wrapKey', 'unwrapKey']),
2291cb0ef41Sopenharmony_ci  ]);
2301cb0ef41Sopenharmony_ci
2311cb0ef41Sopenharmony_ci  const wrappedKey = await subtle.wrapKey(format, key, wrappingKey, 'AES-KW');
2321cb0ef41Sopenharmony_ci
2331cb0ef41Sopenharmony_ci  return { wrappedKey, wrappingKey };
2341cb0ef41Sopenharmony_ci}
2351cb0ef41Sopenharmony_ci
2361cb0ef41Sopenharmony_ciasync function unwrapHmacKey(
2371cb0ef41Sopenharmony_ci  wrappedKey,
2381cb0ef41Sopenharmony_ci  wrappingKey,
2391cb0ef41Sopenharmony_ci  format = 'jwk',
2401cb0ef41Sopenharmony_ci  hash = 'SHA-512') {
2411cb0ef41Sopenharmony_ci
2421cb0ef41Sopenharmony_ci  const key = await subtle.unwrapKey(
2431cb0ef41Sopenharmony_ci    format,
2441cb0ef41Sopenharmony_ci    wrappedKey,
2451cb0ef41Sopenharmony_ci    wrappingKey,
2461cb0ef41Sopenharmony_ci    'AES-KW',
2471cb0ef41Sopenharmony_ci    { name: 'HMAC', hash },
2481cb0ef41Sopenharmony_ci    true,
2491cb0ef41Sopenharmony_ci    ['sign', 'verify']);
2501cb0ef41Sopenharmony_ci
2511cb0ef41Sopenharmony_ci  return key;
2521cb0ef41Sopenharmony_ci}
2531cb0ef41Sopenharmony_ci```
2541cb0ef41Sopenharmony_ci
2551cb0ef41Sopenharmony_ci### Sign and verify
2561cb0ef41Sopenharmony_ci
2571cb0ef41Sopenharmony_ci```js
2581cb0ef41Sopenharmony_ciconst { subtle } = require('node:crypto').webcrypto;
2591cb0ef41Sopenharmony_ci
2601cb0ef41Sopenharmony_ciasync function sign(key, data) {
2611cb0ef41Sopenharmony_ci  const ec = new TextEncoder();
2621cb0ef41Sopenharmony_ci  const signature =
2631cb0ef41Sopenharmony_ci    await subtle.sign('RSASSA-PKCS1-v1_5', key, ec.encode(data));
2641cb0ef41Sopenharmony_ci  return signature;
2651cb0ef41Sopenharmony_ci}
2661cb0ef41Sopenharmony_ci
2671cb0ef41Sopenharmony_ciasync function verify(key, signature, data) {
2681cb0ef41Sopenharmony_ci  const ec = new TextEncoder();
2691cb0ef41Sopenharmony_ci  const verified =
2701cb0ef41Sopenharmony_ci    await subtle.verify(
2711cb0ef41Sopenharmony_ci      'RSASSA-PKCS1-v1_5',
2721cb0ef41Sopenharmony_ci      key,
2731cb0ef41Sopenharmony_ci      signature,
2741cb0ef41Sopenharmony_ci      ec.encode(data));
2751cb0ef41Sopenharmony_ci  return verified;
2761cb0ef41Sopenharmony_ci}
2771cb0ef41Sopenharmony_ci```
2781cb0ef41Sopenharmony_ci
2791cb0ef41Sopenharmony_ci### Deriving bits and keys
2801cb0ef41Sopenharmony_ci
2811cb0ef41Sopenharmony_ci```js
2821cb0ef41Sopenharmony_ciconst { subtle } = require('node:crypto').webcrypto;
2831cb0ef41Sopenharmony_ci
2841cb0ef41Sopenharmony_ciasync function pbkdf2(pass, salt, iterations = 1000, length = 256) {
2851cb0ef41Sopenharmony_ci  const ec = new TextEncoder();
2861cb0ef41Sopenharmony_ci  const key = await subtle.importKey(
2871cb0ef41Sopenharmony_ci    'raw',
2881cb0ef41Sopenharmony_ci    ec.encode(pass),
2891cb0ef41Sopenharmony_ci    'PBKDF2',
2901cb0ef41Sopenharmony_ci    false,
2911cb0ef41Sopenharmony_ci    ['deriveBits']);
2921cb0ef41Sopenharmony_ci  const bits = await subtle.deriveBits({
2931cb0ef41Sopenharmony_ci    name: 'PBKDF2',
2941cb0ef41Sopenharmony_ci    hash: 'SHA-512',
2951cb0ef41Sopenharmony_ci    salt: ec.encode(salt),
2961cb0ef41Sopenharmony_ci    iterations,
2971cb0ef41Sopenharmony_ci  }, key, length);
2981cb0ef41Sopenharmony_ci  return bits;
2991cb0ef41Sopenharmony_ci}
3001cb0ef41Sopenharmony_ci
3011cb0ef41Sopenharmony_ciasync function pbkdf2Key(pass, salt, iterations = 1000, length = 256) {
3021cb0ef41Sopenharmony_ci  const ec = new TextEncoder();
3031cb0ef41Sopenharmony_ci  const keyMaterial = await subtle.importKey(
3041cb0ef41Sopenharmony_ci    'raw',
3051cb0ef41Sopenharmony_ci    ec.encode(pass),
3061cb0ef41Sopenharmony_ci    'PBKDF2',
3071cb0ef41Sopenharmony_ci    false,
3081cb0ef41Sopenharmony_ci    ['deriveKey']);
3091cb0ef41Sopenharmony_ci  const key = await subtle.deriveKey({
3101cb0ef41Sopenharmony_ci    name: 'PBKDF2',
3111cb0ef41Sopenharmony_ci    hash: 'SHA-512',
3121cb0ef41Sopenharmony_ci    salt: ec.encode(salt),
3131cb0ef41Sopenharmony_ci    iterations,
3141cb0ef41Sopenharmony_ci  }, keyMaterial, {
3151cb0ef41Sopenharmony_ci    name: 'AES-GCM',
3161cb0ef41Sopenharmony_ci    length: 256,
3171cb0ef41Sopenharmony_ci  }, true, ['encrypt', 'decrypt']);
3181cb0ef41Sopenharmony_ci  return key;
3191cb0ef41Sopenharmony_ci}
3201cb0ef41Sopenharmony_ci```
3211cb0ef41Sopenharmony_ci
3221cb0ef41Sopenharmony_ci### Digest
3231cb0ef41Sopenharmony_ci
3241cb0ef41Sopenharmony_ci```js
3251cb0ef41Sopenharmony_ciconst { subtle } = require('node:crypto').webcrypto;
3261cb0ef41Sopenharmony_ci
3271cb0ef41Sopenharmony_ciasync function digest(data, algorithm = 'SHA-512') {
3281cb0ef41Sopenharmony_ci  const ec = new TextEncoder();
3291cb0ef41Sopenharmony_ci  const digest = await subtle.digest(algorithm, ec.encode(data));
3301cb0ef41Sopenharmony_ci  return digest;
3311cb0ef41Sopenharmony_ci}
3321cb0ef41Sopenharmony_ci```
3331cb0ef41Sopenharmony_ci
3341cb0ef41Sopenharmony_ci## Algorithm matrix
3351cb0ef41Sopenharmony_ci
3361cb0ef41Sopenharmony_ciThe table details the algorithms supported by the Node.js Web Crypto API
3371cb0ef41Sopenharmony_ciimplementation and the APIs supported for each:
3381cb0ef41Sopenharmony_ci
3391cb0ef41Sopenharmony_ci| Algorithm                                                 | `generateKey` | `exportKey` | `importKey` | `encrypt` | `decrypt` | `wrapKey` | `unwrapKey` | `deriveBits` | `deriveKey` | `sign` | `verify` | `digest` |
3401cb0ef41Sopenharmony_ci| --------------------------------------------------------- | ------------- | ----------- | ----------- | --------- | --------- | --------- | ----------- | ------------ | ----------- | ------ | -------- | -------- |
3411cb0ef41Sopenharmony_ci| `'RSASSA-PKCS1-v1_5'`                                     | ✔             | ✔           | ✔           |           |           |           |             |              |             | ✔      | ✔        |          |
3421cb0ef41Sopenharmony_ci| `'RSA-PSS'`                                               | ✔             | ✔           | ✔           |           |           |           |             |              |             | ✔      | ✔        |          |
3431cb0ef41Sopenharmony_ci| `'RSA-OAEP'`                                              | ✔             | ✔           | ✔           | ✔         | ✔         | ✔         | ✔           |              |             |        |          |          |
3441cb0ef41Sopenharmony_ci| `'ECDSA'`                                                 | ✔             | ✔           | ✔           |           |           |           |             |              |             | ✔      | ✔        |          |
3451cb0ef41Sopenharmony_ci| `'Ed25519'` <span class="experimental-inline"></span>[^1] | ✔             | ✔           | ✔           |           |           |           |             |              |             | ✔      | ✔        |          |
3461cb0ef41Sopenharmony_ci| `'Ed448'` <span class="experimental-inline"></span>[^1]   | ✔             | ✔           | ✔           |           |           |           |             |              |             | ✔      | ✔        |          |
3471cb0ef41Sopenharmony_ci| `'ECDH'`                                                  | ✔             | ✔           | ✔           |           |           |           |             | ✔            | ✔           |        |          |          |
3481cb0ef41Sopenharmony_ci| `'X25519'` <span class="experimental-inline"></span>[^1]  | ✔             | ✔           | ✔           |           |           |           |             | ✔            | ✔           |        |          |          |
3491cb0ef41Sopenharmony_ci| `'X448'` <span class="experimental-inline"></span>[^1]    | ✔             | ✔           | ✔           |           |           |           |             | ✔            | ✔           |        |          |          |
3501cb0ef41Sopenharmony_ci| `'AES-CTR'`                                               | ✔             | ✔           | ✔           | ✔         | ✔         | ✔         | ✔           |              |             |        |          |          |
3511cb0ef41Sopenharmony_ci| `'AES-CBC'`                                               | ✔             | ✔           | ✔           | ✔         | ✔         | ✔         | ✔           |              |             |        |          |          |
3521cb0ef41Sopenharmony_ci| `'AES-GCM'`                                               | ✔             | ✔           | ✔           | ✔         | ✔         | ✔         | ✔           |              |             |        |          |          |
3531cb0ef41Sopenharmony_ci| `'AES-KW'`                                                | ✔             | ✔           | ✔           |           |           | ✔         | ✔           |              |             |        |          |          |
3541cb0ef41Sopenharmony_ci| `'HMAC'`                                                  | ✔             | ✔           | ✔           |           |           |           |             |              |             | ✔      | ✔        |          |
3551cb0ef41Sopenharmony_ci| `'HKDF'`                                                  |               | ✔           | ✔           |           |           |           |             | ✔            | ✔           |        |          |          |
3561cb0ef41Sopenharmony_ci| `'PBKDF2'`                                                |               | ✔           | ✔           |           |           |           |             | ✔            | ✔           |        |          |          |
3571cb0ef41Sopenharmony_ci| `'SHA-1'`                                                 |               |             |             |           |           |           |             |              |             |        |          | ✔        |
3581cb0ef41Sopenharmony_ci| `'SHA-256'`                                               |               |             |             |           |           |           |             |              |             |        |          | ✔        |
3591cb0ef41Sopenharmony_ci| `'SHA-384'`                                               |               |             |             |           |           |           |             |              |             |        |          | ✔        |
3601cb0ef41Sopenharmony_ci| `'SHA-512'`                                               |               |             |             |           |           |           |             |              |             |        |          | ✔        |
3611cb0ef41Sopenharmony_ci
3621cb0ef41Sopenharmony_ci## Class: `Crypto`
3631cb0ef41Sopenharmony_ci
3641cb0ef41Sopenharmony_ci<!-- YAML
3651cb0ef41Sopenharmony_ciadded: v15.0.0
3661cb0ef41Sopenharmony_ci-->
3671cb0ef41Sopenharmony_ci
3681cb0ef41Sopenharmony_ciCalling `require('node:crypto').webcrypto` returns an instance of the `Crypto`
3691cb0ef41Sopenharmony_ciclass. `Crypto` is a singleton that provides access to the remainder of the
3701cb0ef41Sopenharmony_cicrypto API.
3711cb0ef41Sopenharmony_ci
3721cb0ef41Sopenharmony_ci### `crypto.subtle`
3731cb0ef41Sopenharmony_ci
3741cb0ef41Sopenharmony_ci<!-- YAML
3751cb0ef41Sopenharmony_ciadded: v15.0.0
3761cb0ef41Sopenharmony_ci-->
3771cb0ef41Sopenharmony_ci
3781cb0ef41Sopenharmony_ci* Type: {SubtleCrypto}
3791cb0ef41Sopenharmony_ci
3801cb0ef41Sopenharmony_ciProvides access to the `SubtleCrypto` API.
3811cb0ef41Sopenharmony_ci
3821cb0ef41Sopenharmony_ci### `crypto.getRandomValues(typedArray)`
3831cb0ef41Sopenharmony_ci
3841cb0ef41Sopenharmony_ci<!-- YAML
3851cb0ef41Sopenharmony_ciadded: v15.0.0
3861cb0ef41Sopenharmony_ci-->
3871cb0ef41Sopenharmony_ci
3881cb0ef41Sopenharmony_ci* `typedArray` {Buffer|TypedArray}
3891cb0ef41Sopenharmony_ci* Returns: {Buffer|TypedArray}
3901cb0ef41Sopenharmony_ci
3911cb0ef41Sopenharmony_ciGenerates cryptographically strong random values. The given `typedArray` is
3921cb0ef41Sopenharmony_cifilled with random values, and a reference to `typedArray` is returned.
3931cb0ef41Sopenharmony_ci
3941cb0ef41Sopenharmony_ciThe given `typedArray` must be an integer-based instance of {TypedArray},
3951cb0ef41Sopenharmony_cii.e. `Float32Array` and `Float64Array` are not accepted.
3961cb0ef41Sopenharmony_ci
3971cb0ef41Sopenharmony_ciAn error will be thrown if the given `typedArray` is larger than 65,536 bytes.
3981cb0ef41Sopenharmony_ci
3991cb0ef41Sopenharmony_ci### `crypto.randomUUID()`
4001cb0ef41Sopenharmony_ci
4011cb0ef41Sopenharmony_ci<!-- YAML
4021cb0ef41Sopenharmony_ciadded: v16.7.0
4031cb0ef41Sopenharmony_ci-->
4041cb0ef41Sopenharmony_ci
4051cb0ef41Sopenharmony_ci* Returns: {string}
4061cb0ef41Sopenharmony_ci
4071cb0ef41Sopenharmony_ciGenerates a random [RFC 4122][] version 4 UUID. The UUID is generated using a
4081cb0ef41Sopenharmony_cicryptographic pseudorandom number generator.
4091cb0ef41Sopenharmony_ci
4101cb0ef41Sopenharmony_ci## Class: `CryptoKey`
4111cb0ef41Sopenharmony_ci
4121cb0ef41Sopenharmony_ci<!-- YAML
4131cb0ef41Sopenharmony_ciadded: v15.0.0
4141cb0ef41Sopenharmony_ci-->
4151cb0ef41Sopenharmony_ci
4161cb0ef41Sopenharmony_ci### `cryptoKey.algorithm`
4171cb0ef41Sopenharmony_ci
4181cb0ef41Sopenharmony_ci<!-- YAML
4191cb0ef41Sopenharmony_ciadded: v15.0.0
4201cb0ef41Sopenharmony_ci-->
4211cb0ef41Sopenharmony_ci
4221cb0ef41Sopenharmony_ci<!--lint disable maximum-line-length remark-lint-->
4231cb0ef41Sopenharmony_ci
4241cb0ef41Sopenharmony_ci* Type: {AesKeyGenParams|RsaHashedKeyGenParams|EcKeyGenParams|HmacKeyGenParams}
4251cb0ef41Sopenharmony_ci
4261cb0ef41Sopenharmony_ci<!--lint enable maximum-line-length remark-lint-->
4271cb0ef41Sopenharmony_ci
4281cb0ef41Sopenharmony_ciAn object detailing the algorithm for which the key can be used along with
4291cb0ef41Sopenharmony_ciadditional algorithm-specific parameters.
4301cb0ef41Sopenharmony_ci
4311cb0ef41Sopenharmony_ciRead-only.
4321cb0ef41Sopenharmony_ci
4331cb0ef41Sopenharmony_ci### `cryptoKey.extractable`
4341cb0ef41Sopenharmony_ci
4351cb0ef41Sopenharmony_ci<!-- YAML
4361cb0ef41Sopenharmony_ciadded: v15.0.0
4371cb0ef41Sopenharmony_ci-->
4381cb0ef41Sopenharmony_ci
4391cb0ef41Sopenharmony_ci* Type: {boolean}
4401cb0ef41Sopenharmony_ci
4411cb0ef41Sopenharmony_ciWhen `true`, the {CryptoKey} can be extracted using either
4421cb0ef41Sopenharmony_ci`subtleCrypto.exportKey()` or `subtleCrypto.wrapKey()`.
4431cb0ef41Sopenharmony_ci
4441cb0ef41Sopenharmony_ciRead-only.
4451cb0ef41Sopenharmony_ci
4461cb0ef41Sopenharmony_ci### `cryptoKey.type`
4471cb0ef41Sopenharmony_ci
4481cb0ef41Sopenharmony_ci<!-- YAML
4491cb0ef41Sopenharmony_ciadded: v15.0.0
4501cb0ef41Sopenharmony_ci-->
4511cb0ef41Sopenharmony_ci
4521cb0ef41Sopenharmony_ci* Type: {string} One of `'secret'`, `'private'`, or `'public'`.
4531cb0ef41Sopenharmony_ci
4541cb0ef41Sopenharmony_ciA string identifying whether the key is a symmetric (`'secret'`) or
4551cb0ef41Sopenharmony_ciasymmetric (`'private'` or `'public'`) key.
4561cb0ef41Sopenharmony_ci
4571cb0ef41Sopenharmony_ci### `cryptoKey.usages`
4581cb0ef41Sopenharmony_ci
4591cb0ef41Sopenharmony_ci<!-- YAML
4601cb0ef41Sopenharmony_ciadded: v15.0.0
4611cb0ef41Sopenharmony_ci-->
4621cb0ef41Sopenharmony_ci
4631cb0ef41Sopenharmony_ci* Type: {string\[]}
4641cb0ef41Sopenharmony_ci
4651cb0ef41Sopenharmony_ciAn array of strings identifying the operations for which the
4661cb0ef41Sopenharmony_cikey may be used.
4671cb0ef41Sopenharmony_ci
4681cb0ef41Sopenharmony_ciThe possible usages are:
4691cb0ef41Sopenharmony_ci
4701cb0ef41Sopenharmony_ci* `'encrypt'` - The key may be used to encrypt data.
4711cb0ef41Sopenharmony_ci* `'decrypt'` - The key may be used to decrypt data.
4721cb0ef41Sopenharmony_ci* `'sign'` - The key may be used to generate digital signatures.
4731cb0ef41Sopenharmony_ci* `'verify'` - The key may be used to verify digital signatures.
4741cb0ef41Sopenharmony_ci* `'deriveKey'` - The key may be used to derive a new key.
4751cb0ef41Sopenharmony_ci* `'deriveBits'` - The key may be used to derive bits.
4761cb0ef41Sopenharmony_ci* `'wrapKey'` - The key may be used to wrap another key.
4771cb0ef41Sopenharmony_ci* `'unwrapKey'` - The key may be used to unwrap another key.
4781cb0ef41Sopenharmony_ci
4791cb0ef41Sopenharmony_ciValid key usages depend on the key algorithm (identified by
4801cb0ef41Sopenharmony_ci`cryptokey.algorithm.name`).
4811cb0ef41Sopenharmony_ci
4821cb0ef41Sopenharmony_ci| Key Type                                                  | `'encrypt'` | `'decrypt'` | `'sign'` | `'verify'` | `'deriveKey'` | `'deriveBits'` | `'wrapKey'` | `'unwrapKey'` |
4831cb0ef41Sopenharmony_ci| --------------------------------------------------------- | ----------- | ----------- | -------- | ---------- | ------------- | -------------- | ----------- | ------------- |
4841cb0ef41Sopenharmony_ci| `'AES-CBC'`                                               | ✔           | ✔           |          |            |               |                | ✔           | ✔             |
4851cb0ef41Sopenharmony_ci| `'AES-CTR'`                                               | ✔           | ✔           |          |            |               |                | ✔           | ✔             |
4861cb0ef41Sopenharmony_ci| `'AES-GCM'`                                               | ✔           | ✔           |          |            |               |                | ✔           | ✔             |
4871cb0ef41Sopenharmony_ci| `'AES-KW'`                                                |             |             |          |            |               |                | ✔           | ✔             |
4881cb0ef41Sopenharmony_ci| `'ECDH'`                                                  |             |             |          |            | ✔             | ✔              |             |               |
4891cb0ef41Sopenharmony_ci| `'X25519'` <span class="experimental-inline"></span>[^1]  |             |             |          |            | ✔             | ✔              |             |               |
4901cb0ef41Sopenharmony_ci| `'X448'` <span class="experimental-inline"></span>[^1]    |             |             |          |            | ✔             | ✔              |             |               |
4911cb0ef41Sopenharmony_ci| `'ECDSA'`                                                 |             |             | ✔        | ✔          |               |                |             |               |
4921cb0ef41Sopenharmony_ci| `'Ed25519'` <span class="experimental-inline"></span>[^1] |             |             | ✔        | ✔          |               |                |             |               |
4931cb0ef41Sopenharmony_ci| `'Ed448'` <span class="experimental-inline"></span>[^1]   |             |             | ✔        | ✔          |               |                |             |               |
4941cb0ef41Sopenharmony_ci| `'HDKF'`                                                  |             |             |          |            | ✔             | ✔              |             |               |
4951cb0ef41Sopenharmony_ci| `'HMAC'`                                                  |             |             | ✔        | ✔          |               |                |             |               |
4961cb0ef41Sopenharmony_ci| `'PBKDF2'`                                                |             |             |          |            | ✔             | ✔              |             |               |
4971cb0ef41Sopenharmony_ci| `'RSA-OAEP'`                                              | ✔           | ✔           |          |            |               |                | ✔           | ✔             |
4981cb0ef41Sopenharmony_ci| `'RSA-PSS'`                                               |             |             | ✔        | ✔          |               |                |             |               |
4991cb0ef41Sopenharmony_ci| `'RSASSA-PKCS1-v1_5'`                                     |             |             | ✔        | ✔          |               |                |             |               |
5001cb0ef41Sopenharmony_ci
5011cb0ef41Sopenharmony_ci## Class: `CryptoKeyPair`
5021cb0ef41Sopenharmony_ci
5031cb0ef41Sopenharmony_ci<!-- YAML
5041cb0ef41Sopenharmony_ciadded: v15.0.0
5051cb0ef41Sopenharmony_ci-->
5061cb0ef41Sopenharmony_ci
5071cb0ef41Sopenharmony_ciThe `CryptoKeyPair` is a simple dictionary object with `publicKey` and
5081cb0ef41Sopenharmony_ci`privateKey` properties, representing an asymmetric key pair.
5091cb0ef41Sopenharmony_ci
5101cb0ef41Sopenharmony_ci### `cryptoKeyPair.privateKey`
5111cb0ef41Sopenharmony_ci
5121cb0ef41Sopenharmony_ci<!-- YAML
5131cb0ef41Sopenharmony_ciadded: v15.0.0
5141cb0ef41Sopenharmony_ci-->
5151cb0ef41Sopenharmony_ci
5161cb0ef41Sopenharmony_ci* Type: {CryptoKey} A {CryptoKey} whose `type` will be `'private'`.
5171cb0ef41Sopenharmony_ci
5181cb0ef41Sopenharmony_ci### `cryptoKeyPair.publicKey`
5191cb0ef41Sopenharmony_ci
5201cb0ef41Sopenharmony_ci<!-- YAML
5211cb0ef41Sopenharmony_ciadded: v15.0.0
5221cb0ef41Sopenharmony_ci-->
5231cb0ef41Sopenharmony_ci
5241cb0ef41Sopenharmony_ci* Type: {CryptoKey} A {CryptoKey} whose `type` will be `'public'`.
5251cb0ef41Sopenharmony_ci
5261cb0ef41Sopenharmony_ci## Class: `SubtleCrypto`
5271cb0ef41Sopenharmony_ci
5281cb0ef41Sopenharmony_ci<!-- YAML
5291cb0ef41Sopenharmony_ciadded: v15.0.0
5301cb0ef41Sopenharmony_ci-->
5311cb0ef41Sopenharmony_ci
5321cb0ef41Sopenharmony_ci### `subtle.decrypt(algorithm, key, data)`
5331cb0ef41Sopenharmony_ci
5341cb0ef41Sopenharmony_ci<!-- YAML
5351cb0ef41Sopenharmony_ciadded: v15.0.0
5361cb0ef41Sopenharmony_ci-->
5371cb0ef41Sopenharmony_ci
5381cb0ef41Sopenharmony_ci* `algorithm`: {RsaOaepParams|AesCtrParams|AesCbcParams|AesGcmParams}
5391cb0ef41Sopenharmony_ci* `key`: {CryptoKey}
5401cb0ef41Sopenharmony_ci* `data`: {ArrayBuffer|TypedArray|DataView|Buffer}
5411cb0ef41Sopenharmony_ci* Returns: {Promise} containing {ArrayBuffer}
5421cb0ef41Sopenharmony_ci
5431cb0ef41Sopenharmony_ciUsing the method and parameters specified in `algorithm` and the keying
5441cb0ef41Sopenharmony_cimaterial provided by `key`, `subtle.decrypt()` attempts to decipher the
5451cb0ef41Sopenharmony_ciprovided `data`. If successful, the returned promise will be resolved with
5461cb0ef41Sopenharmony_cian {ArrayBuffer} containing the plaintext result.
5471cb0ef41Sopenharmony_ci
5481cb0ef41Sopenharmony_ciThe algorithms currently supported include:
5491cb0ef41Sopenharmony_ci
5501cb0ef41Sopenharmony_ci* `'RSA-OAEP'`
5511cb0ef41Sopenharmony_ci* `'AES-CTR'`
5521cb0ef41Sopenharmony_ci* `'AES-CBC'`
5531cb0ef41Sopenharmony_ci* `'AES-GCM`'
5541cb0ef41Sopenharmony_ci
5551cb0ef41Sopenharmony_ci### `subtle.deriveBits(algorithm, baseKey, length)`
5561cb0ef41Sopenharmony_ci
5571cb0ef41Sopenharmony_ci<!-- YAML
5581cb0ef41Sopenharmony_ciadded: v15.0.0
5591cb0ef41Sopenharmony_cichanges:
5601cb0ef41Sopenharmony_ci  - version: v18.4.0
5611cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/42507
5621cb0ef41Sopenharmony_ci    description: Added `'X25519'`, and `'X448'` algorithms.
5631cb0ef41Sopenharmony_ci-->
5641cb0ef41Sopenharmony_ci
5651cb0ef41Sopenharmony_ci<!--lint disable maximum-line-length remark-lint-->
5661cb0ef41Sopenharmony_ci
5671cb0ef41Sopenharmony_ci* `algorithm`: {AlgorithmIdentifier|EcdhKeyDeriveParams|HkdfParams|Pbkdf2Params}
5681cb0ef41Sopenharmony_ci* `baseKey`: {CryptoKey}
5691cb0ef41Sopenharmony_ci* `length`: {number|null}
5701cb0ef41Sopenharmony_ci* Returns: {Promise} containing {ArrayBuffer}
5711cb0ef41Sopenharmony_ci
5721cb0ef41Sopenharmony_ci<!--lint enable maximum-line-length remark-lint-->
5731cb0ef41Sopenharmony_ci
5741cb0ef41Sopenharmony_ciUsing the method and parameters specified in `algorithm` and the keying
5751cb0ef41Sopenharmony_cimaterial provided by `baseKey`, `subtle.deriveBits()` attempts to generate
5761cb0ef41Sopenharmony_ci`length` bits.
5771cb0ef41Sopenharmony_ci
5781cb0ef41Sopenharmony_ciThe Node.js implementation requires that when `length` is a
5791cb0ef41Sopenharmony_cinumber it must be multiple of `8`.
5801cb0ef41Sopenharmony_ci
5811cb0ef41Sopenharmony_ciWhen `length` is `null` the maximum number of bits for a given algorithm is
5821cb0ef41Sopenharmony_cigenerated. This is allowed for the `'ECDH'`, `'X25519'`, and `'X448'`
5831cb0ef41Sopenharmony_cialgorithms.
5841cb0ef41Sopenharmony_ci
5851cb0ef41Sopenharmony_ciIf successful, the returned promise will be resolved with an {ArrayBuffer}
5861cb0ef41Sopenharmony_cicontaining the generated data.
5871cb0ef41Sopenharmony_ci
5881cb0ef41Sopenharmony_ciThe algorithms currently supported include:
5891cb0ef41Sopenharmony_ci
5901cb0ef41Sopenharmony_ci* `'ECDH'`
5911cb0ef41Sopenharmony_ci* `'X25519'` <span class="experimental-inline"></span>[^1]
5921cb0ef41Sopenharmony_ci* `'X448'` <span class="experimental-inline"></span>[^1]
5931cb0ef41Sopenharmony_ci* `'HKDF'`
5941cb0ef41Sopenharmony_ci* `'PBKDF2'`
5951cb0ef41Sopenharmony_ci
5961cb0ef41Sopenharmony_ci### `subtle.deriveKey(algorithm, baseKey, derivedKeyAlgorithm, extractable, keyUsages)`
5971cb0ef41Sopenharmony_ci
5981cb0ef41Sopenharmony_ci<!-- YAML
5991cb0ef41Sopenharmony_ciadded: v15.0.0
6001cb0ef41Sopenharmony_cichanges:
6011cb0ef41Sopenharmony_ci  - version: v18.4.0
6021cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/42507
6031cb0ef41Sopenharmony_ci    description: Added `'X25519'`, and `'X448'` algorithms.
6041cb0ef41Sopenharmony_ci-->
6051cb0ef41Sopenharmony_ci
6061cb0ef41Sopenharmony_ci<!--lint disable maximum-line-length remark-lint-->
6071cb0ef41Sopenharmony_ci
6081cb0ef41Sopenharmony_ci* `algorithm`: {AlgorithmIdentifier|EcdhKeyDeriveParams|HkdfParams|Pbkdf2Params}
6091cb0ef41Sopenharmony_ci* `baseKey`: {CryptoKey}
6101cb0ef41Sopenharmony_ci* `derivedKeyAlgorithm`: {HmacKeyGenParams|AesKeyGenParams}
6111cb0ef41Sopenharmony_ci* `extractable`: {boolean}
6121cb0ef41Sopenharmony_ci* `keyUsages`: {string\[]} See [Key usages][].
6131cb0ef41Sopenharmony_ci* Returns: {Promise} containing {CryptoKey}
6141cb0ef41Sopenharmony_ci
6151cb0ef41Sopenharmony_ci<!--lint enable maximum-line-length remark-lint-->
6161cb0ef41Sopenharmony_ci
6171cb0ef41Sopenharmony_ciUsing the method and parameters specified in `algorithm`, and the keying
6181cb0ef41Sopenharmony_cimaterial provided by `baseKey`, `subtle.deriveKey()` attempts to generate
6191cb0ef41Sopenharmony_cia new {CryptoKey} based on the method and parameters in `derivedKeyAlgorithm`.
6201cb0ef41Sopenharmony_ci
6211cb0ef41Sopenharmony_ciCalling `subtle.deriveKey()` is equivalent to calling `subtle.deriveBits()` to
6221cb0ef41Sopenharmony_cigenerate raw keying material, then passing the result into the
6231cb0ef41Sopenharmony_ci`subtle.importKey()` method using the `deriveKeyAlgorithm`, `extractable`, and
6241cb0ef41Sopenharmony_ci`keyUsages` parameters as input.
6251cb0ef41Sopenharmony_ci
6261cb0ef41Sopenharmony_ciThe algorithms currently supported include:
6271cb0ef41Sopenharmony_ci
6281cb0ef41Sopenharmony_ci* `'ECDH'`
6291cb0ef41Sopenharmony_ci* `'X25519'` <span class="experimental-inline"></span>[^1]
6301cb0ef41Sopenharmony_ci* `'X448'` <span class="experimental-inline"></span>[^1]
6311cb0ef41Sopenharmony_ci* `'HKDF'`
6321cb0ef41Sopenharmony_ci* `'PBKDF2'`
6331cb0ef41Sopenharmony_ci
6341cb0ef41Sopenharmony_ci### `subtle.digest(algorithm, data)`
6351cb0ef41Sopenharmony_ci
6361cb0ef41Sopenharmony_ci<!-- YAML
6371cb0ef41Sopenharmony_ciadded: v15.0.0
6381cb0ef41Sopenharmony_ci-->
6391cb0ef41Sopenharmony_ci
6401cb0ef41Sopenharmony_ci* `algorithm`: {string|Object}
6411cb0ef41Sopenharmony_ci* `data`: {ArrayBuffer|TypedArray|DataView|Buffer}
6421cb0ef41Sopenharmony_ci* Returns: {Promise} containing {ArrayBuffer}
6431cb0ef41Sopenharmony_ci
6441cb0ef41Sopenharmony_ciUsing the method identified by `algorithm`, `subtle.digest()` attempts to
6451cb0ef41Sopenharmony_cigenerate a digest of `data`. If successful, the returned promise is resolved
6461cb0ef41Sopenharmony_ciwith an {ArrayBuffer} containing the computed digest.
6471cb0ef41Sopenharmony_ci
6481cb0ef41Sopenharmony_ciIf `algorithm` is provided as a {string}, it must be one of:
6491cb0ef41Sopenharmony_ci
6501cb0ef41Sopenharmony_ci* `'SHA-1'`
6511cb0ef41Sopenharmony_ci* `'SHA-256'`
6521cb0ef41Sopenharmony_ci* `'SHA-384'`
6531cb0ef41Sopenharmony_ci* `'SHA-512'`
6541cb0ef41Sopenharmony_ci
6551cb0ef41Sopenharmony_ciIf `algorithm` is provided as an {Object}, it must have a `name` property
6561cb0ef41Sopenharmony_ciwhose value is one of the above.
6571cb0ef41Sopenharmony_ci
6581cb0ef41Sopenharmony_ci### `subtle.encrypt(algorithm, key, data)`
6591cb0ef41Sopenharmony_ci
6601cb0ef41Sopenharmony_ci<!-- YAML
6611cb0ef41Sopenharmony_ciadded: v15.0.0
6621cb0ef41Sopenharmony_ci-->
6631cb0ef41Sopenharmony_ci
6641cb0ef41Sopenharmony_ci* `algorithm`: {RsaOaepParams|AesCtrParams|AesCbcParams|AesGcmParams}
6651cb0ef41Sopenharmony_ci* `key`: {CryptoKey}
6661cb0ef41Sopenharmony_ci* Returns: {Promise} containing {ArrayBuffer}
6671cb0ef41Sopenharmony_ci
6681cb0ef41Sopenharmony_ciUsing the method and parameters specified by `algorithm` and the keying
6691cb0ef41Sopenharmony_cimaterial provided by `key`, `subtle.encrypt()` attempts to encipher `data`.
6701cb0ef41Sopenharmony_ciIf successful, the returned promise is resolved with an {ArrayBuffer}
6711cb0ef41Sopenharmony_cicontaining the encrypted result.
6721cb0ef41Sopenharmony_ci
6731cb0ef41Sopenharmony_ciThe algorithms currently supported include:
6741cb0ef41Sopenharmony_ci
6751cb0ef41Sopenharmony_ci* `'RSA-OAEP'`
6761cb0ef41Sopenharmony_ci* `'AES-CTR'`
6771cb0ef41Sopenharmony_ci* `'AES-CBC'`
6781cb0ef41Sopenharmony_ci* `'AES-GCM`'
6791cb0ef41Sopenharmony_ci
6801cb0ef41Sopenharmony_ci### `subtle.exportKey(format, key)`
6811cb0ef41Sopenharmony_ci
6821cb0ef41Sopenharmony_ci<!-- YAML
6831cb0ef41Sopenharmony_ciadded: v15.0.0
6841cb0ef41Sopenharmony_cichanges:
6851cb0ef41Sopenharmony_ci  - version: v18.4.0
6861cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/42507
6871cb0ef41Sopenharmony_ci    description: Added `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'`
6881cb0ef41Sopenharmony_ci      algorithms.
6891cb0ef41Sopenharmony_ci  - version: v15.9.0
6901cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/37203
6911cb0ef41Sopenharmony_ci    description: Removed `'NODE-DSA'` JWK export.
6921cb0ef41Sopenharmony_ci-->
6931cb0ef41Sopenharmony_ci
6941cb0ef41Sopenharmony_ci* `format`: {string} Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
6951cb0ef41Sopenharmony_ci* `key`: {CryptoKey}
6961cb0ef41Sopenharmony_ci* Returns: {Promise} containing {ArrayBuffer|Object}.
6971cb0ef41Sopenharmony_ci
6981cb0ef41Sopenharmony_ciExports the given key into the specified format, if supported.
6991cb0ef41Sopenharmony_ci
7001cb0ef41Sopenharmony_ciIf the {CryptoKey} is not extractable, the returned promise will reject.
7011cb0ef41Sopenharmony_ci
7021cb0ef41Sopenharmony_ciWhen `format` is either `'pkcs8'` or `'spki'` and the export is successful,
7031cb0ef41Sopenharmony_cithe returned promise will be resolved with an {ArrayBuffer} containing the
7041cb0ef41Sopenharmony_ciexported key data.
7051cb0ef41Sopenharmony_ci
7061cb0ef41Sopenharmony_ciWhen `format` is `'jwk'` and the export is successful, the returned promise
7071cb0ef41Sopenharmony_ciwill be resolved with a JavaScript object conforming to the [JSON Web Key][]
7081cb0ef41Sopenharmony_cispecification.
7091cb0ef41Sopenharmony_ci
7101cb0ef41Sopenharmony_ci| Key Type                                                  | `'spki'` | `'pkcs8'` | `'jwk'` | `'raw'` |
7111cb0ef41Sopenharmony_ci| --------------------------------------------------------- | -------- | --------- | ------- | ------- |
7121cb0ef41Sopenharmony_ci| `'AES-CBC'`                                               |          |           | ✔       | ✔       |
7131cb0ef41Sopenharmony_ci| `'AES-CTR'`                                               |          |           | ✔       | ✔       |
7141cb0ef41Sopenharmony_ci| `'AES-GCM'`                                               |          |           | ✔       | ✔       |
7151cb0ef41Sopenharmony_ci| `'AES-KW'`                                                |          |           | ✔       | ✔       |
7161cb0ef41Sopenharmony_ci| `'ECDH'`                                                  | ✔        | ✔         | ✔       | ✔       |
7171cb0ef41Sopenharmony_ci| `'ECDSA'`                                                 | ✔        | ✔         | ✔       | ✔       |
7181cb0ef41Sopenharmony_ci| `'Ed25519'` <span class="experimental-inline"></span>[^1] | ✔        | ✔         | ✔       | ✔       |
7191cb0ef41Sopenharmony_ci| `'Ed448'` <span class="experimental-inline"></span>[^1]   | ✔        | ✔         | ✔       | ✔       |
7201cb0ef41Sopenharmony_ci| `'HDKF'`                                                  |          |           |         |         |
7211cb0ef41Sopenharmony_ci| `'HMAC'`                                                  |          |           | ✔       | ✔       |
7221cb0ef41Sopenharmony_ci| `'PBKDF2'`                                                |          |           |         |         |
7231cb0ef41Sopenharmony_ci| `'RSA-OAEP'`                                              | ✔        | ✔         | ✔       |         |
7241cb0ef41Sopenharmony_ci| `'RSA-PSS'`                                               | ✔        | ✔         | ✔       |         |
7251cb0ef41Sopenharmony_ci| `'RSASSA-PKCS1-v1_5'`                                     | ✔        | ✔         | ✔       |         |
7261cb0ef41Sopenharmony_ci
7271cb0ef41Sopenharmony_ci### `subtle.generateKey(algorithm, extractable, keyUsages)`
7281cb0ef41Sopenharmony_ci
7291cb0ef41Sopenharmony_ci<!-- YAML
7301cb0ef41Sopenharmony_ciadded: v15.0.0
7311cb0ef41Sopenharmony_ci-->
7321cb0ef41Sopenharmony_ci
7331cb0ef41Sopenharmony_ci<!--lint disable maximum-line-length remark-lint-->
7341cb0ef41Sopenharmony_ci
7351cb0ef41Sopenharmony_ci* `algorithm`: {AlgorithmIdentifier|RsaHashedKeyGenParams|EcKeyGenParams|HmacKeyGenParams|AesKeyGenParams}
7361cb0ef41Sopenharmony_ci
7371cb0ef41Sopenharmony_ci<!--lint enable maximum-line-length remark-lint-->
7381cb0ef41Sopenharmony_ci
7391cb0ef41Sopenharmony_ci* `extractable`: {boolean}
7401cb0ef41Sopenharmony_ci* `keyUsages`: {string\[]} See [Key usages][].
7411cb0ef41Sopenharmony_ci* Returns: {Promise} containing {CryptoKey|CryptoKeyPair}
7421cb0ef41Sopenharmony_ci
7431cb0ef41Sopenharmony_ciUsing the method and parameters provided in `algorithm`, `subtle.generateKey()`
7441cb0ef41Sopenharmony_ciattempts to generate new keying material. Depending the method used, the method
7451cb0ef41Sopenharmony_cimay generate either a single {CryptoKey} or a {CryptoKeyPair}.
7461cb0ef41Sopenharmony_ci
7471cb0ef41Sopenharmony_ciThe {CryptoKeyPair} (public and private key) generating algorithms supported
7481cb0ef41Sopenharmony_ciinclude:
7491cb0ef41Sopenharmony_ci
7501cb0ef41Sopenharmony_ci* `'RSASSA-PKCS1-v1_5'`
7511cb0ef41Sopenharmony_ci* `'RSA-PSS'`
7521cb0ef41Sopenharmony_ci* `'RSA-OAEP'`
7531cb0ef41Sopenharmony_ci* `'ECDSA'`
7541cb0ef41Sopenharmony_ci* `'Ed25519'` <span class="experimental-inline"></span>[^1]
7551cb0ef41Sopenharmony_ci* `'Ed448'` <span class="experimental-inline"></span>[^1]
7561cb0ef41Sopenharmony_ci* `'ECDH'`
7571cb0ef41Sopenharmony_ci* `'X25519'` <span class="experimental-inline"></span>[^1]
7581cb0ef41Sopenharmony_ci* `'X448'` <span class="experimental-inline"></span>[^1]
7591cb0ef41Sopenharmony_ci
7601cb0ef41Sopenharmony_ciThe {CryptoKey} (secret key) generating algorithms supported include:
7611cb0ef41Sopenharmony_ci
7621cb0ef41Sopenharmony_ci* `'HMAC'`
7631cb0ef41Sopenharmony_ci* `'AES-CTR'`
7641cb0ef41Sopenharmony_ci* `'AES-CBC'`
7651cb0ef41Sopenharmony_ci* `'AES-GCM'`
7661cb0ef41Sopenharmony_ci* `'AES-KW'`
7671cb0ef41Sopenharmony_ci
7681cb0ef41Sopenharmony_ci### `subtle.importKey(format, keyData, algorithm, extractable, keyUsages)`
7691cb0ef41Sopenharmony_ci
7701cb0ef41Sopenharmony_ci<!-- YAML
7711cb0ef41Sopenharmony_ciadded: v15.0.0
7721cb0ef41Sopenharmony_cichanges:
7731cb0ef41Sopenharmony_ci  - version: v18.4.0
7741cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/42507
7751cb0ef41Sopenharmony_ci    description: Added `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'`
7761cb0ef41Sopenharmony_ci      algorithms.
7771cb0ef41Sopenharmony_ci  - version: v15.9.0
7781cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/37203
7791cb0ef41Sopenharmony_ci    description: Removed `'NODE-DSA'` JWK import.
7801cb0ef41Sopenharmony_ci-->
7811cb0ef41Sopenharmony_ci
7821cb0ef41Sopenharmony_ci* `format`: {string} Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
7831cb0ef41Sopenharmony_ci* `keyData`: {ArrayBuffer|TypedArray|DataView|Buffer|Object}
7841cb0ef41Sopenharmony_ci
7851cb0ef41Sopenharmony_ci<!--lint disable maximum-line-length remark-lint-->
7861cb0ef41Sopenharmony_ci
7871cb0ef41Sopenharmony_ci* `algorithm`: {AlgorithmIdentifier|RsaHashedImportParams|EcKeyImportParams|HmacImportParams}
7881cb0ef41Sopenharmony_ci
7891cb0ef41Sopenharmony_ci<!--lint enable maximum-line-length remark-lint-->
7901cb0ef41Sopenharmony_ci
7911cb0ef41Sopenharmony_ci* `extractable`: {boolean}
7921cb0ef41Sopenharmony_ci* `keyUsages`: {string\[]} See [Key usages][].
7931cb0ef41Sopenharmony_ci* Returns: {Promise} containing {CryptoKey}
7941cb0ef41Sopenharmony_ci
7951cb0ef41Sopenharmony_ciThe `subtle.importKey()` method attempts to interpret the provided `keyData`
7961cb0ef41Sopenharmony_cias the given `format` to create a {CryptoKey} instance using the provided
7971cb0ef41Sopenharmony_ci`algorithm`, `extractable`, and `keyUsages` arguments. If the import is
7981cb0ef41Sopenharmony_cisuccessful, the returned promise will be resolved with the created {CryptoKey}.
7991cb0ef41Sopenharmony_ci
8001cb0ef41Sopenharmony_ciIf importing a `'PBKDF2'` key, `extractable` must be `false`.
8011cb0ef41Sopenharmony_ci
8021cb0ef41Sopenharmony_ciThe algorithms currently supported include:
8031cb0ef41Sopenharmony_ci
8041cb0ef41Sopenharmony_ci| Key Type                                                  | `'spki'` | `'pkcs8'` | `'jwk'` | `'raw'` |
8051cb0ef41Sopenharmony_ci| --------------------------------------------------------- | -------- | --------- | ------- | ------- |
8061cb0ef41Sopenharmony_ci| `'AES-CBC'`                                               |          |           | ✔       | ✔       |
8071cb0ef41Sopenharmony_ci| `'AES-CTR'`                                               |          |           | ✔       | ✔       |
8081cb0ef41Sopenharmony_ci| `'AES-GCM'`                                               |          |           | ✔       | ✔       |
8091cb0ef41Sopenharmony_ci| `'AES-KW'`                                                |          |           | ✔       | ✔       |
8101cb0ef41Sopenharmony_ci| `'ECDH'`                                                  | ✔        | ✔         | ✔       | ✔       |
8111cb0ef41Sopenharmony_ci| `'X25519'` <span class="experimental-inline"></span>[^1]  | ✔        | ✔         | ✔       | ✔       |
8121cb0ef41Sopenharmony_ci| `'X448'` <span class="experimental-inline"></span>[^1]    | ✔        | ✔         | ✔       | ✔       |
8131cb0ef41Sopenharmony_ci| `'ECDSA'`                                                 | ✔        | ✔         | ✔       | ✔       |
8141cb0ef41Sopenharmony_ci| `'Ed25519'` <span class="experimental-inline"></span>[^1] | ✔        | ✔         | ✔       | ✔       |
8151cb0ef41Sopenharmony_ci| `'Ed448'` <span class="experimental-inline"></span>[^1]   | ✔        | ✔         | ✔       | ✔       |
8161cb0ef41Sopenharmony_ci| `'HDKF'`                                                  |          |           |         | ✔       |
8171cb0ef41Sopenharmony_ci| `'HMAC'`                                                  |          |           | ✔       | ✔       |
8181cb0ef41Sopenharmony_ci| `'PBKDF2'`                                                |          |           |         | ✔       |
8191cb0ef41Sopenharmony_ci| `'RSA-OAEP'`                                              | ✔        | ✔         | ✔       |         |
8201cb0ef41Sopenharmony_ci| `'RSA-PSS'`                                               | ✔        | ✔         | ✔       |         |
8211cb0ef41Sopenharmony_ci| `'RSASSA-PKCS1-v1_5'`                                     | ✔        | ✔         | ✔       |         |
8221cb0ef41Sopenharmony_ci
8231cb0ef41Sopenharmony_ci### `subtle.sign(algorithm, key, data)`
8241cb0ef41Sopenharmony_ci
8251cb0ef41Sopenharmony_ci<!-- YAML
8261cb0ef41Sopenharmony_ciadded: v15.0.0
8271cb0ef41Sopenharmony_cichanges:
8281cb0ef41Sopenharmony_ci  - version: v18.4.0
8291cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/42507
8301cb0ef41Sopenharmony_ci    description: Added `'Ed25519'`, and `'Ed448'` algorithms.
8311cb0ef41Sopenharmony_ci-->
8321cb0ef41Sopenharmony_ci
8331cb0ef41Sopenharmony_ci<!--lint disable maximum-line-length remark-lint-->
8341cb0ef41Sopenharmony_ci
8351cb0ef41Sopenharmony_ci* `algorithm`: {AlgorithmIdentifier|RsaPssParams|EcdsaParams|Ed448Params}
8361cb0ef41Sopenharmony_ci* `key`: {CryptoKey}
8371cb0ef41Sopenharmony_ci* `data`: {ArrayBuffer|TypedArray|DataView|Buffer}
8381cb0ef41Sopenharmony_ci* Returns: {Promise} containing {ArrayBuffer}
8391cb0ef41Sopenharmony_ci
8401cb0ef41Sopenharmony_ci<!--lint enable maximum-line-length remark-lint-->
8411cb0ef41Sopenharmony_ci
8421cb0ef41Sopenharmony_ciUsing the method and parameters given by `algorithm` and the keying material
8431cb0ef41Sopenharmony_ciprovided by `key`, `subtle.sign()` attempts to generate a cryptographic
8441cb0ef41Sopenharmony_cisignature of `data`. If successful, the returned promise is resolved with
8451cb0ef41Sopenharmony_cian {ArrayBuffer} containing the generated signature.
8461cb0ef41Sopenharmony_ci
8471cb0ef41Sopenharmony_ciThe algorithms currently supported include:
8481cb0ef41Sopenharmony_ci
8491cb0ef41Sopenharmony_ci* `'RSASSA-PKCS1-v1_5'`
8501cb0ef41Sopenharmony_ci* `'RSA-PSS'`
8511cb0ef41Sopenharmony_ci* `'ECDSA'`
8521cb0ef41Sopenharmony_ci* `'Ed25519'` <span class="experimental-inline"></span>[^1]
8531cb0ef41Sopenharmony_ci* `'Ed448'` <span class="experimental-inline"></span>[^1]
8541cb0ef41Sopenharmony_ci* `'HMAC'`
8551cb0ef41Sopenharmony_ci
8561cb0ef41Sopenharmony_ci### `subtle.unwrapKey(format, wrappedKey, unwrappingKey, unwrapAlgo, unwrappedKeyAlgo, extractable, keyUsages)`
8571cb0ef41Sopenharmony_ci
8581cb0ef41Sopenharmony_ci<!-- YAML
8591cb0ef41Sopenharmony_ciadded: v15.0.0
8601cb0ef41Sopenharmony_ci-->
8611cb0ef41Sopenharmony_ci
8621cb0ef41Sopenharmony_ci* `format`: {string} Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
8631cb0ef41Sopenharmony_ci* `wrappedKey`: {ArrayBuffer|TypedArray|DataView|Buffer}
8641cb0ef41Sopenharmony_ci* `unwrappingKey`: {CryptoKey}
8651cb0ef41Sopenharmony_ci
8661cb0ef41Sopenharmony_ci<!--lint disable maximum-line-length remark-lint-->
8671cb0ef41Sopenharmony_ci
8681cb0ef41Sopenharmony_ci* `unwrapAlgo`: {AlgorithmIdentifier|RsaOaepParams|AesCtrParams|AesCbcParams|AesGcmParams}
8691cb0ef41Sopenharmony_ci* `unwrappedKeyAlgo`: {AlgorithmIdentifier|RsaHashedImportParams|EcKeyImportParams|HmacImportParams}
8701cb0ef41Sopenharmony_ci
8711cb0ef41Sopenharmony_ci<!--lint enable maximum-line-length remark-lint-->
8721cb0ef41Sopenharmony_ci
8731cb0ef41Sopenharmony_ci* `extractable`: {boolean}
8741cb0ef41Sopenharmony_ci* `keyUsages`: {string\[]} See [Key usages][].
8751cb0ef41Sopenharmony_ci* Returns: {Promise} containing {CryptoKey}
8761cb0ef41Sopenharmony_ci
8771cb0ef41Sopenharmony_ciIn cryptography, "wrapping a key" refers to exporting and then encrypting the
8781cb0ef41Sopenharmony_cikeying material. The `subtle.unwrapKey()` method attempts to decrypt a wrapped
8791cb0ef41Sopenharmony_cikey and create a {CryptoKey} instance. It is equivalent to calling
8801cb0ef41Sopenharmony_ci`subtle.decrypt()` first on the encrypted key data (using the `wrappedKey`,
8811cb0ef41Sopenharmony_ci`unwrapAlgo`, and `unwrappingKey` arguments as input) then passing the results
8821cb0ef41Sopenharmony_ciin to the `subtle.importKey()` method using the `unwrappedKeyAlgo`,
8831cb0ef41Sopenharmony_ci`extractable`, and `keyUsages` arguments as inputs. If successful, the returned
8841cb0ef41Sopenharmony_cipromise is resolved with a {CryptoKey} object.
8851cb0ef41Sopenharmony_ci
8861cb0ef41Sopenharmony_ciThe wrapping algorithms currently supported include:
8871cb0ef41Sopenharmony_ci
8881cb0ef41Sopenharmony_ci* `'RSA-OAEP'`
8891cb0ef41Sopenharmony_ci* `'AES-CTR'`
8901cb0ef41Sopenharmony_ci* `'AES-CBC'`
8911cb0ef41Sopenharmony_ci* `'AES-GCM'`
8921cb0ef41Sopenharmony_ci* `'AES-KW'`
8931cb0ef41Sopenharmony_ci
8941cb0ef41Sopenharmony_ciThe unwrapped key algorithms supported include:
8951cb0ef41Sopenharmony_ci
8961cb0ef41Sopenharmony_ci* `'RSASSA-PKCS1-v1_5'`
8971cb0ef41Sopenharmony_ci* `'RSA-PSS'`
8981cb0ef41Sopenharmony_ci* `'RSA-OAEP'`
8991cb0ef41Sopenharmony_ci* `'ECDSA'`
9001cb0ef41Sopenharmony_ci* `'Ed25519'` <span class="experimental-inline"></span>[^1]
9011cb0ef41Sopenharmony_ci* `'Ed448'` <span class="experimental-inline"></span>[^1]
9021cb0ef41Sopenharmony_ci* `'ECDH'`
9031cb0ef41Sopenharmony_ci* `'X25519'` <span class="experimental-inline"></span>[^1]
9041cb0ef41Sopenharmony_ci* `'X448'` <span class="experimental-inline"></span>[^1]
9051cb0ef41Sopenharmony_ci* `'HMAC'`
9061cb0ef41Sopenharmony_ci* `'AES-CTR'`
9071cb0ef41Sopenharmony_ci* `'AES-CBC'`
9081cb0ef41Sopenharmony_ci* `'AES-GCM'`
9091cb0ef41Sopenharmony_ci* `'AES-KW'`
9101cb0ef41Sopenharmony_ci
9111cb0ef41Sopenharmony_ci### `subtle.verify(algorithm, key, signature, data)`
9121cb0ef41Sopenharmony_ci
9131cb0ef41Sopenharmony_ci<!-- YAML
9141cb0ef41Sopenharmony_ciadded: v15.0.0
9151cb0ef41Sopenharmony_cichanges:
9161cb0ef41Sopenharmony_ci  - version: v18.4.0
9171cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/42507
9181cb0ef41Sopenharmony_ci    description: Added `'Ed25519'`, and `'Ed448'` algorithms.
9191cb0ef41Sopenharmony_ci-->
9201cb0ef41Sopenharmony_ci
9211cb0ef41Sopenharmony_ci<!--lint disable maximum-line-length remark-lint-->
9221cb0ef41Sopenharmony_ci
9231cb0ef41Sopenharmony_ci* `algorithm`: {AlgorithmIdentifier|RsaPssParams|EcdsaParams|Ed448Params}
9241cb0ef41Sopenharmony_ci* `key`: {CryptoKey}
9251cb0ef41Sopenharmony_ci* `signature`: {ArrayBuffer|TypedArray|DataView|Buffer}
9261cb0ef41Sopenharmony_ci* `data`: {ArrayBuffer|TypedArray|DataView|Buffer}
9271cb0ef41Sopenharmony_ci* Returns: {Promise} containing {boolean}
9281cb0ef41Sopenharmony_ci
9291cb0ef41Sopenharmony_ci<!--lint enable maximum-line-length remark-lint-->
9301cb0ef41Sopenharmony_ci
9311cb0ef41Sopenharmony_ciUsing the method and parameters given in `algorithm` and the keying material
9321cb0ef41Sopenharmony_ciprovided by `key`, `subtle.verify()` attempts to verify that `signature` is
9331cb0ef41Sopenharmony_cia valid cryptographic signature of `data`. The returned promise is resolved
9341cb0ef41Sopenharmony_ciwith either `true` or `false`.
9351cb0ef41Sopenharmony_ci
9361cb0ef41Sopenharmony_ciThe algorithms currently supported include:
9371cb0ef41Sopenharmony_ci
9381cb0ef41Sopenharmony_ci* `'RSASSA-PKCS1-v1_5'`
9391cb0ef41Sopenharmony_ci* `'RSA-PSS'`
9401cb0ef41Sopenharmony_ci* `'ECDSA'`
9411cb0ef41Sopenharmony_ci* `'Ed25519'` <span class="experimental-inline"></span>[^1]
9421cb0ef41Sopenharmony_ci* `'Ed448'` <span class="experimental-inline"></span>[^1]
9431cb0ef41Sopenharmony_ci* `'HMAC'`
9441cb0ef41Sopenharmony_ci
9451cb0ef41Sopenharmony_ci### `subtle.wrapKey(format, key, wrappingKey, wrapAlgo)`
9461cb0ef41Sopenharmony_ci
9471cb0ef41Sopenharmony_ci<!-- YAML
9481cb0ef41Sopenharmony_ciadded: v15.0.0
9491cb0ef41Sopenharmony_ci-->
9501cb0ef41Sopenharmony_ci
9511cb0ef41Sopenharmony_ci<!--lint disable maximum-line-length remark-lint-->
9521cb0ef41Sopenharmony_ci
9531cb0ef41Sopenharmony_ci* `format`: {string} Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
9541cb0ef41Sopenharmony_ci* `key`: {CryptoKey}
9551cb0ef41Sopenharmony_ci* `wrappingKey`: {CryptoKey}
9561cb0ef41Sopenharmony_ci* `wrapAlgo`: {AlgorithmIdentifier|RsaOaepParams|AesCtrParams|AesCbcParams|AesGcmParams}
9571cb0ef41Sopenharmony_ci* Returns: {Promise} containing {ArrayBuffer}
9581cb0ef41Sopenharmony_ci
9591cb0ef41Sopenharmony_ci<!--lint enable maximum-line-length remark-lint-->
9601cb0ef41Sopenharmony_ci
9611cb0ef41Sopenharmony_ciIn cryptography, "wrapping a key" refers to exporting and then encrypting the
9621cb0ef41Sopenharmony_cikeying material. The `subtle.wrapKey()` method exports the keying material into
9631cb0ef41Sopenharmony_cithe format identified by `format`, then encrypts it using the method and
9641cb0ef41Sopenharmony_ciparameters specified by `wrapAlgo` and the keying material provided by
9651cb0ef41Sopenharmony_ci`wrappingKey`. It is the equivalent to calling `subtle.exportKey()` using
9661cb0ef41Sopenharmony_ci`format` and `key` as the arguments, then passing the result to the
9671cb0ef41Sopenharmony_ci`subtle.encrypt()` method using `wrappingKey` and `wrapAlgo` as inputs. If
9681cb0ef41Sopenharmony_cisuccessful, the returned promise will be resolved with an {ArrayBuffer}
9691cb0ef41Sopenharmony_cicontaining the encrypted key data.
9701cb0ef41Sopenharmony_ci
9711cb0ef41Sopenharmony_ciThe wrapping algorithms currently supported include:
9721cb0ef41Sopenharmony_ci
9731cb0ef41Sopenharmony_ci* `'RSA-OAEP'`
9741cb0ef41Sopenharmony_ci* `'AES-CTR'`
9751cb0ef41Sopenharmony_ci* `'AES-CBC'`
9761cb0ef41Sopenharmony_ci* `'AES-GCM'`
9771cb0ef41Sopenharmony_ci* `'AES-KW'`
9781cb0ef41Sopenharmony_ci
9791cb0ef41Sopenharmony_ci## Algorithm parameters
9801cb0ef41Sopenharmony_ci
9811cb0ef41Sopenharmony_ciThe algorithm parameter objects define the methods and parameters used by
9821cb0ef41Sopenharmony_cithe various {SubtleCrypto} methods. While described here as "classes", they
9831cb0ef41Sopenharmony_ciare simple JavaScript dictionary objects.
9841cb0ef41Sopenharmony_ci
9851cb0ef41Sopenharmony_ci### Class: `AlgorithmIdentifier`
9861cb0ef41Sopenharmony_ci
9871cb0ef41Sopenharmony_ci<!-- YAML
9881cb0ef41Sopenharmony_ciadded: v18.4.0
9891cb0ef41Sopenharmony_ci-->
9901cb0ef41Sopenharmony_ci
9911cb0ef41Sopenharmony_ci#### `algorithmIdentifier.name`
9921cb0ef41Sopenharmony_ci
9931cb0ef41Sopenharmony_ci<!-- YAML
9941cb0ef41Sopenharmony_ciadded: v18.4.0
9951cb0ef41Sopenharmony_ci-->
9961cb0ef41Sopenharmony_ci
9971cb0ef41Sopenharmony_ci* Type: {string}
9981cb0ef41Sopenharmony_ci
9991cb0ef41Sopenharmony_ci### Class: `AesCbcParams`
10001cb0ef41Sopenharmony_ci
10011cb0ef41Sopenharmony_ci<!-- YAML
10021cb0ef41Sopenharmony_ciadded: v15.0.0
10031cb0ef41Sopenharmony_ci-->
10041cb0ef41Sopenharmony_ci
10051cb0ef41Sopenharmony_ci#### `aesCbcParams.iv`
10061cb0ef41Sopenharmony_ci
10071cb0ef41Sopenharmony_ci<!-- YAML
10081cb0ef41Sopenharmony_ciadded: v15.0.0
10091cb0ef41Sopenharmony_ci-->
10101cb0ef41Sopenharmony_ci
10111cb0ef41Sopenharmony_ci* Type: {ArrayBuffer|TypedArray|DataView|Buffer}
10121cb0ef41Sopenharmony_ci
10131cb0ef41Sopenharmony_ciProvides the initialization vector. It must be exactly 16-bytes in length
10141cb0ef41Sopenharmony_ciand should be unpredictable and cryptographically random.
10151cb0ef41Sopenharmony_ci
10161cb0ef41Sopenharmony_ci#### `aesCbcParams.name`
10171cb0ef41Sopenharmony_ci
10181cb0ef41Sopenharmony_ci<!-- YAML
10191cb0ef41Sopenharmony_ciadded: v15.0.0
10201cb0ef41Sopenharmony_ci-->
10211cb0ef41Sopenharmony_ci
10221cb0ef41Sopenharmony_ci* Type: {string} Must be `'AES-CBC'`.
10231cb0ef41Sopenharmony_ci
10241cb0ef41Sopenharmony_ci### Class: `AesCtrParams`
10251cb0ef41Sopenharmony_ci
10261cb0ef41Sopenharmony_ci<!-- YAML
10271cb0ef41Sopenharmony_ciadded: v15.0.0
10281cb0ef41Sopenharmony_ci-->
10291cb0ef41Sopenharmony_ci
10301cb0ef41Sopenharmony_ci#### `aesCtrParams.counter`
10311cb0ef41Sopenharmony_ci
10321cb0ef41Sopenharmony_ci<!-- YAML
10331cb0ef41Sopenharmony_ciadded: v15.0.0
10341cb0ef41Sopenharmony_ci-->
10351cb0ef41Sopenharmony_ci
10361cb0ef41Sopenharmony_ci* Type: {ArrayBuffer|TypedArray|DataView|Buffer}
10371cb0ef41Sopenharmony_ci
10381cb0ef41Sopenharmony_ciThe initial value of the counter block. This must be exactly 16 bytes long.
10391cb0ef41Sopenharmony_ci
10401cb0ef41Sopenharmony_ciThe `AES-CTR` method uses the rightmost `length` bits of the block as the
10411cb0ef41Sopenharmony_cicounter and the remaining bits as the nonce.
10421cb0ef41Sopenharmony_ci
10431cb0ef41Sopenharmony_ci#### `aesCtrParams.length`
10441cb0ef41Sopenharmony_ci
10451cb0ef41Sopenharmony_ci<!-- YAML
10461cb0ef41Sopenharmony_ciadded: v15.0.0
10471cb0ef41Sopenharmony_ci-->
10481cb0ef41Sopenharmony_ci
10491cb0ef41Sopenharmony_ci* Type: {number} The number of bits in the `aesCtrParams.counter` that are
10501cb0ef41Sopenharmony_ci  to be used as the counter.
10511cb0ef41Sopenharmony_ci
10521cb0ef41Sopenharmony_ci#### `aesCtrParams.name`
10531cb0ef41Sopenharmony_ci
10541cb0ef41Sopenharmony_ci<!-- YAML
10551cb0ef41Sopenharmony_ciadded: v15.0.0
10561cb0ef41Sopenharmony_ci-->
10571cb0ef41Sopenharmony_ci
10581cb0ef41Sopenharmony_ci* Type: {string} Must be `'AES-CTR'`.
10591cb0ef41Sopenharmony_ci
10601cb0ef41Sopenharmony_ci### Class: `AesGcmParams`
10611cb0ef41Sopenharmony_ci
10621cb0ef41Sopenharmony_ci<!-- YAML
10631cb0ef41Sopenharmony_ciadded: v15.0.0
10641cb0ef41Sopenharmony_ci-->
10651cb0ef41Sopenharmony_ci
10661cb0ef41Sopenharmony_ci#### `aesGcmParams.additionalData`
10671cb0ef41Sopenharmony_ci
10681cb0ef41Sopenharmony_ci<!-- YAML
10691cb0ef41Sopenharmony_ciadded: v15.0.0
10701cb0ef41Sopenharmony_ci-->
10711cb0ef41Sopenharmony_ci
10721cb0ef41Sopenharmony_ci* Type: {ArrayBuffer|TypedArray|DataView|Buffer|undefined}
10731cb0ef41Sopenharmony_ci
10741cb0ef41Sopenharmony_ciWith the AES-GCM method, the `additionalData` is extra input that is not
10751cb0ef41Sopenharmony_ciencrypted but is included in the authentication of the data. The use of
10761cb0ef41Sopenharmony_ci`additionalData` is optional.
10771cb0ef41Sopenharmony_ci
10781cb0ef41Sopenharmony_ci#### `aesGcmParams.iv`
10791cb0ef41Sopenharmony_ci
10801cb0ef41Sopenharmony_ci<!-- YAML
10811cb0ef41Sopenharmony_ciadded: v15.0.0
10821cb0ef41Sopenharmony_ci-->
10831cb0ef41Sopenharmony_ci
10841cb0ef41Sopenharmony_ci* Type: {ArrayBuffer|TypedArray|DataView|Buffer}
10851cb0ef41Sopenharmony_ci
10861cb0ef41Sopenharmony_ciThe initialization vector must be unique for every encryption operation using a
10871cb0ef41Sopenharmony_cigiven key.
10881cb0ef41Sopenharmony_ci
10891cb0ef41Sopenharmony_ciIdeally, this is a deterministic 12-byte value that is computed in such a way
10901cb0ef41Sopenharmony_cithat it is guaranteed to be unique across all invocations that use the same key.
10911cb0ef41Sopenharmony_ciAlternatively, the initialization vector may consist of at least 12
10921cb0ef41Sopenharmony_cicryptographically random bytes. For more information on constructing
10931cb0ef41Sopenharmony_ciinitialization vectors for AES-GCM, refer to Section 8 of [NIST SP 800-38D][].
10941cb0ef41Sopenharmony_ci
10951cb0ef41Sopenharmony_ci#### `aesGcmParams.name`
10961cb0ef41Sopenharmony_ci
10971cb0ef41Sopenharmony_ci<!-- YAML
10981cb0ef41Sopenharmony_ciadded: v15.0.0
10991cb0ef41Sopenharmony_ci-->
11001cb0ef41Sopenharmony_ci
11011cb0ef41Sopenharmony_ci* Type: {string} Must be `'AES-GCM'`.
11021cb0ef41Sopenharmony_ci
11031cb0ef41Sopenharmony_ci#### `aesGcmParams.tagLength`
11041cb0ef41Sopenharmony_ci
11051cb0ef41Sopenharmony_ci<!-- YAML
11061cb0ef41Sopenharmony_ciadded: v15.0.0
11071cb0ef41Sopenharmony_ci-->
11081cb0ef41Sopenharmony_ci
11091cb0ef41Sopenharmony_ci* Type: {number} The size in bits of the generated authentication tag.
11101cb0ef41Sopenharmony_ci  This values must be one of `32`, `64`, `96`, `104`, `112`, `120`, or
11111cb0ef41Sopenharmony_ci  `128`. **Default:** `128`.
11121cb0ef41Sopenharmony_ci
11131cb0ef41Sopenharmony_ci### Class: `AesKeyGenParams`
11141cb0ef41Sopenharmony_ci
11151cb0ef41Sopenharmony_ci<!-- YAML
11161cb0ef41Sopenharmony_ciadded: v15.0.0
11171cb0ef41Sopenharmony_ci-->
11181cb0ef41Sopenharmony_ci
11191cb0ef41Sopenharmony_ci#### `aesKeyGenParams.length`
11201cb0ef41Sopenharmony_ci
11211cb0ef41Sopenharmony_ci<!-- YAML
11221cb0ef41Sopenharmony_ciadded: v15.0.0
11231cb0ef41Sopenharmony_ci-->
11241cb0ef41Sopenharmony_ci
11251cb0ef41Sopenharmony_ci* Type: {number}
11261cb0ef41Sopenharmony_ci
11271cb0ef41Sopenharmony_ciThe length of the AES key to be generated. This must be either `128`, `192`,
11281cb0ef41Sopenharmony_cior `256`.
11291cb0ef41Sopenharmony_ci
11301cb0ef41Sopenharmony_ci#### `aesKeyGenParams.name`
11311cb0ef41Sopenharmony_ci
11321cb0ef41Sopenharmony_ci<!-- YAML
11331cb0ef41Sopenharmony_ciadded: v15.0.0
11341cb0ef41Sopenharmony_ci-->
11351cb0ef41Sopenharmony_ci
11361cb0ef41Sopenharmony_ci* Type: {string} Must be one of `'AES-CBC'`, `'AES-CTR'`, `'AES-GCM'`, or
11371cb0ef41Sopenharmony_ci  `'AES-KW'`
11381cb0ef41Sopenharmony_ci
11391cb0ef41Sopenharmony_ci### Class: `EcdhKeyDeriveParams`
11401cb0ef41Sopenharmony_ci
11411cb0ef41Sopenharmony_ci<!-- YAML
11421cb0ef41Sopenharmony_ciadded: v15.0.0
11431cb0ef41Sopenharmony_ci-->
11441cb0ef41Sopenharmony_ci
11451cb0ef41Sopenharmony_ci#### `ecdhKeyDeriveParams.name`
11461cb0ef41Sopenharmony_ci
11471cb0ef41Sopenharmony_ci<!-- YAML
11481cb0ef41Sopenharmony_ciadded: v15.0.0
11491cb0ef41Sopenharmony_ci-->
11501cb0ef41Sopenharmony_ci
11511cb0ef41Sopenharmony_ci* Type: {string} Must be `'ECDH'`, `'X25519'`, or `'X448'`.
11521cb0ef41Sopenharmony_ci
11531cb0ef41Sopenharmony_ci#### `ecdhKeyDeriveParams.public`
11541cb0ef41Sopenharmony_ci
11551cb0ef41Sopenharmony_ci<!-- YAML
11561cb0ef41Sopenharmony_ciadded: v15.0.0
11571cb0ef41Sopenharmony_ci-->
11581cb0ef41Sopenharmony_ci
11591cb0ef41Sopenharmony_ci* Type: {CryptoKey}
11601cb0ef41Sopenharmony_ci
11611cb0ef41Sopenharmony_ciECDH key derivation operates by taking as input one parties private key and
11621cb0ef41Sopenharmony_cianother parties public key -- using both to generate a common shared secret.
11631cb0ef41Sopenharmony_ciThe `ecdhKeyDeriveParams.public` property is set to the other parties public
11641cb0ef41Sopenharmony_cikey.
11651cb0ef41Sopenharmony_ci
11661cb0ef41Sopenharmony_ci### Class: `EcdsaParams`
11671cb0ef41Sopenharmony_ci
11681cb0ef41Sopenharmony_ci<!-- YAML
11691cb0ef41Sopenharmony_ciadded: v15.0.0
11701cb0ef41Sopenharmony_ci-->
11711cb0ef41Sopenharmony_ci
11721cb0ef41Sopenharmony_ci#### `ecdsaParams.hash`
11731cb0ef41Sopenharmony_ci
11741cb0ef41Sopenharmony_ci<!-- YAML
11751cb0ef41Sopenharmony_ciadded: v15.0.0
11761cb0ef41Sopenharmony_ci-->
11771cb0ef41Sopenharmony_ci
11781cb0ef41Sopenharmony_ci* Type: {string|Object}
11791cb0ef41Sopenharmony_ci
11801cb0ef41Sopenharmony_ciIf represented as a {string}, the value must be one of:
11811cb0ef41Sopenharmony_ci
11821cb0ef41Sopenharmony_ci* `'SHA-1'`
11831cb0ef41Sopenharmony_ci* `'SHA-256'`
11841cb0ef41Sopenharmony_ci* `'SHA-384'`
11851cb0ef41Sopenharmony_ci* `'SHA-512'`
11861cb0ef41Sopenharmony_ci
11871cb0ef41Sopenharmony_ciIf represented as an {Object}, the object must have a `name` property
11881cb0ef41Sopenharmony_ciwhose value is one of the above listed values.
11891cb0ef41Sopenharmony_ci
11901cb0ef41Sopenharmony_ci#### `ecdsaParams.name`
11911cb0ef41Sopenharmony_ci
11921cb0ef41Sopenharmony_ci<!-- YAML
11931cb0ef41Sopenharmony_ciadded: v15.0.0
11941cb0ef41Sopenharmony_ci-->
11951cb0ef41Sopenharmony_ci
11961cb0ef41Sopenharmony_ci* Type: {string} Must be `'ECDSA'`.
11971cb0ef41Sopenharmony_ci
11981cb0ef41Sopenharmony_ci### Class: `EcKeyGenParams`
11991cb0ef41Sopenharmony_ci
12001cb0ef41Sopenharmony_ci<!-- YAML
12011cb0ef41Sopenharmony_ciadded: v15.0.0
12021cb0ef41Sopenharmony_ci-->
12031cb0ef41Sopenharmony_ci
12041cb0ef41Sopenharmony_ci#### `ecKeyGenParams.name`
12051cb0ef41Sopenharmony_ci
12061cb0ef41Sopenharmony_ci<!-- YAML
12071cb0ef41Sopenharmony_ciadded: v15.0.0
12081cb0ef41Sopenharmony_ci-->
12091cb0ef41Sopenharmony_ci
12101cb0ef41Sopenharmony_ci* Type: {string} Must be one of `'ECDSA'` or `'ECDH'`.
12111cb0ef41Sopenharmony_ci
12121cb0ef41Sopenharmony_ci#### `ecKeyGenParams.namedCurve`
12131cb0ef41Sopenharmony_ci
12141cb0ef41Sopenharmony_ci<!-- YAML
12151cb0ef41Sopenharmony_ciadded: v15.0.0
12161cb0ef41Sopenharmony_ci-->
12171cb0ef41Sopenharmony_ci
12181cb0ef41Sopenharmony_ci* Type: {string} Must be one of `'P-256'`, `'P-384'`, `'P-521'`.
12191cb0ef41Sopenharmony_ci
12201cb0ef41Sopenharmony_ci### Class: `EcKeyImportParams`
12211cb0ef41Sopenharmony_ci
12221cb0ef41Sopenharmony_ci<!-- YAML
12231cb0ef41Sopenharmony_ciadded: v15.0.0
12241cb0ef41Sopenharmony_ci-->
12251cb0ef41Sopenharmony_ci
12261cb0ef41Sopenharmony_ci#### `ecKeyImportParams.name`
12271cb0ef41Sopenharmony_ci
12281cb0ef41Sopenharmony_ci<!-- YAML
12291cb0ef41Sopenharmony_ciadded: v15.0.0
12301cb0ef41Sopenharmony_ci-->
12311cb0ef41Sopenharmony_ci
12321cb0ef41Sopenharmony_ci* Type: {string} Must be one of `'ECDSA'` or `'ECDH'`.
12331cb0ef41Sopenharmony_ci
12341cb0ef41Sopenharmony_ci#### `ecKeyImportParams.namedCurve`
12351cb0ef41Sopenharmony_ci
12361cb0ef41Sopenharmony_ci<!-- YAML
12371cb0ef41Sopenharmony_ciadded: v15.0.0
12381cb0ef41Sopenharmony_ci-->
12391cb0ef41Sopenharmony_ci
12401cb0ef41Sopenharmony_ci* Type: {string} Must be one of `'P-256'`, `'P-384'`, `'P-521'`.
12411cb0ef41Sopenharmony_ci
12421cb0ef41Sopenharmony_ci### Class: `Ed448Params`
12431cb0ef41Sopenharmony_ci
12441cb0ef41Sopenharmony_ci<!-- YAML
12451cb0ef41Sopenharmony_ciadded: v15.0.0
12461cb0ef41Sopenharmony_ci-->
12471cb0ef41Sopenharmony_ci
12481cb0ef41Sopenharmony_ci#### `ed448Params.name`
12491cb0ef41Sopenharmony_ci
12501cb0ef41Sopenharmony_ci<!-- YAML
12511cb0ef41Sopenharmony_ciadded: v18.4.0
12521cb0ef41Sopenharmony_ci-->
12531cb0ef41Sopenharmony_ci
12541cb0ef41Sopenharmony_ci* Type: {string} Must be `'Ed448'`.
12551cb0ef41Sopenharmony_ci
12561cb0ef41Sopenharmony_ci#### `ed448Params.context`
12571cb0ef41Sopenharmony_ci
12581cb0ef41Sopenharmony_ci<!-- YAML
12591cb0ef41Sopenharmony_ciadded: v18.4.0
12601cb0ef41Sopenharmony_ci-->
12611cb0ef41Sopenharmony_ci
12621cb0ef41Sopenharmony_ci* Type: {ArrayBuffer|TypedArray|DataView|Buffer|undefined}
12631cb0ef41Sopenharmony_ci
12641cb0ef41Sopenharmony_ciThe `context` member represents the optional context data to associate with
12651cb0ef41Sopenharmony_cithe message.
12661cb0ef41Sopenharmony_ciThe Node.js Web Crypto API implementation only supports zero-length context
12671cb0ef41Sopenharmony_ciwhich is equivalent to not providing context at all.
12681cb0ef41Sopenharmony_ci
12691cb0ef41Sopenharmony_ci### Class: `HkdfParams`
12701cb0ef41Sopenharmony_ci
12711cb0ef41Sopenharmony_ci<!-- YAML
12721cb0ef41Sopenharmony_ciadded: v15.0.0
12731cb0ef41Sopenharmony_ci-->
12741cb0ef41Sopenharmony_ci
12751cb0ef41Sopenharmony_ci#### `hkdfParams.hash`
12761cb0ef41Sopenharmony_ci
12771cb0ef41Sopenharmony_ci<!-- YAML
12781cb0ef41Sopenharmony_ciadded: v15.0.0
12791cb0ef41Sopenharmony_ci-->
12801cb0ef41Sopenharmony_ci
12811cb0ef41Sopenharmony_ci* Type: {string|Object}
12821cb0ef41Sopenharmony_ci
12831cb0ef41Sopenharmony_ciIf represented as a {string}, the value must be one of:
12841cb0ef41Sopenharmony_ci
12851cb0ef41Sopenharmony_ci* `'SHA-1'`
12861cb0ef41Sopenharmony_ci* `'SHA-256'`
12871cb0ef41Sopenharmony_ci* `'SHA-384'`
12881cb0ef41Sopenharmony_ci* `'SHA-512'`
12891cb0ef41Sopenharmony_ci
12901cb0ef41Sopenharmony_ciIf represented as an {Object}, the object must have a `name` property
12911cb0ef41Sopenharmony_ciwhose value is one of the above listed values.
12921cb0ef41Sopenharmony_ci
12931cb0ef41Sopenharmony_ci#### `hkdfParams.info`
12941cb0ef41Sopenharmony_ci
12951cb0ef41Sopenharmony_ci<!-- YAML
12961cb0ef41Sopenharmony_ciadded: v15.0.0
12971cb0ef41Sopenharmony_ci-->
12981cb0ef41Sopenharmony_ci
12991cb0ef41Sopenharmony_ci* Type: {ArrayBuffer|TypedArray|DataView|Buffer}
13001cb0ef41Sopenharmony_ci
13011cb0ef41Sopenharmony_ciProvides application-specific contextual input to the HKDF algorithm.
13021cb0ef41Sopenharmony_ciThis can be zero-length but must be provided.
13031cb0ef41Sopenharmony_ci
13041cb0ef41Sopenharmony_ci#### `hkdfParams.name`
13051cb0ef41Sopenharmony_ci
13061cb0ef41Sopenharmony_ci<!-- YAML
13071cb0ef41Sopenharmony_ciadded: v15.0.0
13081cb0ef41Sopenharmony_ci-->
13091cb0ef41Sopenharmony_ci
13101cb0ef41Sopenharmony_ci* Type: {string} Must be `'HKDF'`.
13111cb0ef41Sopenharmony_ci
13121cb0ef41Sopenharmony_ci#### `hkdfParams.salt`
13131cb0ef41Sopenharmony_ci
13141cb0ef41Sopenharmony_ci<!-- YAML
13151cb0ef41Sopenharmony_ciadded: v15.0.0
13161cb0ef41Sopenharmony_ci-->
13171cb0ef41Sopenharmony_ci
13181cb0ef41Sopenharmony_ci* Type: {ArrayBuffer|TypedArray|DataView|Buffer}
13191cb0ef41Sopenharmony_ci
13201cb0ef41Sopenharmony_ciThe salt value significantly improves the strength of the HKDF algorithm.
13211cb0ef41Sopenharmony_ciIt should be random or pseudorandom and should be the same length as the
13221cb0ef41Sopenharmony_cioutput of the digest function (for instance, if using `'SHA-256'` as the
13231cb0ef41Sopenharmony_cidigest, the salt should be 256-bits of random data).
13241cb0ef41Sopenharmony_ci
13251cb0ef41Sopenharmony_ci### Class: `HmacImportParams`
13261cb0ef41Sopenharmony_ci
13271cb0ef41Sopenharmony_ci<!-- YAML
13281cb0ef41Sopenharmony_ciadded: v15.0.0
13291cb0ef41Sopenharmony_ci-->
13301cb0ef41Sopenharmony_ci
13311cb0ef41Sopenharmony_ci#### `hmacImportParams.hash`
13321cb0ef41Sopenharmony_ci
13331cb0ef41Sopenharmony_ci<!-- YAML
13341cb0ef41Sopenharmony_ciadded: v15.0.0
13351cb0ef41Sopenharmony_ci-->
13361cb0ef41Sopenharmony_ci
13371cb0ef41Sopenharmony_ci* Type: {string|Object}
13381cb0ef41Sopenharmony_ci
13391cb0ef41Sopenharmony_ciIf represented as a {string}, the value must be one of:
13401cb0ef41Sopenharmony_ci
13411cb0ef41Sopenharmony_ci* `'SHA-1'`
13421cb0ef41Sopenharmony_ci* `'SHA-256'`
13431cb0ef41Sopenharmony_ci* `'SHA-384'`
13441cb0ef41Sopenharmony_ci* `'SHA-512'`
13451cb0ef41Sopenharmony_ci
13461cb0ef41Sopenharmony_ciIf represented as an {Object}, the object must have a `name` property
13471cb0ef41Sopenharmony_ciwhose value is one of the above listed values.
13481cb0ef41Sopenharmony_ci
13491cb0ef41Sopenharmony_ci#### `hmacImportParams.length`
13501cb0ef41Sopenharmony_ci
13511cb0ef41Sopenharmony_ci<!-- YAML
13521cb0ef41Sopenharmony_ciadded: v15.0.0
13531cb0ef41Sopenharmony_ci-->
13541cb0ef41Sopenharmony_ci
13551cb0ef41Sopenharmony_ci* Type: {number}
13561cb0ef41Sopenharmony_ci
13571cb0ef41Sopenharmony_ciThe optional number of bits in the HMAC key. This is optional and should
13581cb0ef41Sopenharmony_cibe omitted for most cases.
13591cb0ef41Sopenharmony_ci
13601cb0ef41Sopenharmony_ci#### `hmacImportParams.name`
13611cb0ef41Sopenharmony_ci
13621cb0ef41Sopenharmony_ci<!-- YAML
13631cb0ef41Sopenharmony_ciadded: v15.0.0
13641cb0ef41Sopenharmony_ci-->
13651cb0ef41Sopenharmony_ci
13661cb0ef41Sopenharmony_ci* Type: {string} Must be `'HMAC'`.
13671cb0ef41Sopenharmony_ci
13681cb0ef41Sopenharmony_ci### Class: `HmacKeyGenParams`
13691cb0ef41Sopenharmony_ci
13701cb0ef41Sopenharmony_ci<!-- YAML
13711cb0ef41Sopenharmony_ciadded: v15.0.0
13721cb0ef41Sopenharmony_ci-->
13731cb0ef41Sopenharmony_ci
13741cb0ef41Sopenharmony_ci#### `hmacKeyGenParams.hash`
13751cb0ef41Sopenharmony_ci
13761cb0ef41Sopenharmony_ci<!-- YAML
13771cb0ef41Sopenharmony_ciadded: v15.0.0
13781cb0ef41Sopenharmony_ci-->
13791cb0ef41Sopenharmony_ci
13801cb0ef41Sopenharmony_ci* Type: {string|Object}
13811cb0ef41Sopenharmony_ci
13821cb0ef41Sopenharmony_ciIf represented as a {string}, the value must be one of:
13831cb0ef41Sopenharmony_ci
13841cb0ef41Sopenharmony_ci* `'SHA-1'`
13851cb0ef41Sopenharmony_ci* `'SHA-256'`
13861cb0ef41Sopenharmony_ci* `'SHA-384'`
13871cb0ef41Sopenharmony_ci* `'SHA-512'`
13881cb0ef41Sopenharmony_ci
13891cb0ef41Sopenharmony_ciIf represented as an {Object}, the object must have a `name` property
13901cb0ef41Sopenharmony_ciwhose value is one of the above listed values.
13911cb0ef41Sopenharmony_ci
13921cb0ef41Sopenharmony_ci#### `hmacKeyGenParams.length`
13931cb0ef41Sopenharmony_ci
13941cb0ef41Sopenharmony_ci<!-- YAML
13951cb0ef41Sopenharmony_ciadded: v15.0.0
13961cb0ef41Sopenharmony_ci-->
13971cb0ef41Sopenharmony_ci
13981cb0ef41Sopenharmony_ci* Type: {number}
13991cb0ef41Sopenharmony_ci
14001cb0ef41Sopenharmony_ciThe number of bits to generate for the HMAC key. If omitted,
14011cb0ef41Sopenharmony_cithe length will be determined by the hash algorithm used.
14021cb0ef41Sopenharmony_ciThis is optional and should be omitted for most cases.
14031cb0ef41Sopenharmony_ci
14041cb0ef41Sopenharmony_ci#### `hmacKeyGenParams.name`
14051cb0ef41Sopenharmony_ci
14061cb0ef41Sopenharmony_ci<!-- YAML
14071cb0ef41Sopenharmony_ciadded: v15.0.0
14081cb0ef41Sopenharmony_ci-->
14091cb0ef41Sopenharmony_ci
14101cb0ef41Sopenharmony_ci* Type: {string} Must be `'HMAC'`.
14111cb0ef41Sopenharmony_ci
14121cb0ef41Sopenharmony_ci### Class: `Pbkdf2Params`
14131cb0ef41Sopenharmony_ci
14141cb0ef41Sopenharmony_ci<!-- YAML
14151cb0ef41Sopenharmony_ciadded: v15.0.0
14161cb0ef41Sopenharmony_ci-->
14171cb0ef41Sopenharmony_ci
14181cb0ef41Sopenharmony_ci#### `pbkdb2Params.hash`
14191cb0ef41Sopenharmony_ci
14201cb0ef41Sopenharmony_ci<!-- YAML
14211cb0ef41Sopenharmony_ciadded: v15.0.0
14221cb0ef41Sopenharmony_ci-->
14231cb0ef41Sopenharmony_ci
14241cb0ef41Sopenharmony_ci* Type: {string|Object}
14251cb0ef41Sopenharmony_ci
14261cb0ef41Sopenharmony_ciIf represented as a {string}, the value must be one of:
14271cb0ef41Sopenharmony_ci
14281cb0ef41Sopenharmony_ci* `'SHA-1'`
14291cb0ef41Sopenharmony_ci* `'SHA-256'`
14301cb0ef41Sopenharmony_ci* `'SHA-384'`
14311cb0ef41Sopenharmony_ci* `'SHA-512'`
14321cb0ef41Sopenharmony_ci
14331cb0ef41Sopenharmony_ciIf represented as an {Object}, the object must have a `name` property
14341cb0ef41Sopenharmony_ciwhose value is one of the above listed values.
14351cb0ef41Sopenharmony_ci
14361cb0ef41Sopenharmony_ci#### `pbkdf2Params.iterations`
14371cb0ef41Sopenharmony_ci
14381cb0ef41Sopenharmony_ci<!-- YAML
14391cb0ef41Sopenharmony_ciadded: v15.0.0
14401cb0ef41Sopenharmony_ci-->
14411cb0ef41Sopenharmony_ci
14421cb0ef41Sopenharmony_ci* Type: {number}
14431cb0ef41Sopenharmony_ci
14441cb0ef41Sopenharmony_ciThe number of iterations the PBKDF2 algorithm should make when deriving bits.
14451cb0ef41Sopenharmony_ci
14461cb0ef41Sopenharmony_ci#### `pbkdf2Params.name`
14471cb0ef41Sopenharmony_ci
14481cb0ef41Sopenharmony_ci<!-- YAML
14491cb0ef41Sopenharmony_ciadded: v15.0.0
14501cb0ef41Sopenharmony_ci-->
14511cb0ef41Sopenharmony_ci
14521cb0ef41Sopenharmony_ci* Type: {string} Must be `'PBKDF2'`.
14531cb0ef41Sopenharmony_ci
14541cb0ef41Sopenharmony_ci#### `pbkdf2Params.salt`
14551cb0ef41Sopenharmony_ci
14561cb0ef41Sopenharmony_ci<!-- YAML
14571cb0ef41Sopenharmony_ciadded: v15.0.0
14581cb0ef41Sopenharmony_ci-->
14591cb0ef41Sopenharmony_ci
14601cb0ef41Sopenharmony_ci* Type: {ArrayBuffer|TypedArray|DataView|Buffer}
14611cb0ef41Sopenharmony_ci
14621cb0ef41Sopenharmony_ciShould be at least 16 random or pseudorandom bytes.
14631cb0ef41Sopenharmony_ci
14641cb0ef41Sopenharmony_ci### Class: `RsaHashedImportParams`
14651cb0ef41Sopenharmony_ci
14661cb0ef41Sopenharmony_ci<!-- YAML
14671cb0ef41Sopenharmony_ciadded: v15.0.0
14681cb0ef41Sopenharmony_ci-->
14691cb0ef41Sopenharmony_ci
14701cb0ef41Sopenharmony_ci#### `rsaHashedImportParams.hash`
14711cb0ef41Sopenharmony_ci
14721cb0ef41Sopenharmony_ci<!-- YAML
14731cb0ef41Sopenharmony_ciadded: v15.0.0
14741cb0ef41Sopenharmony_ci-->
14751cb0ef41Sopenharmony_ci
14761cb0ef41Sopenharmony_ci* Type: {string|Object}
14771cb0ef41Sopenharmony_ci
14781cb0ef41Sopenharmony_ciIf represented as a {string}, the value must be one of:
14791cb0ef41Sopenharmony_ci
14801cb0ef41Sopenharmony_ci* `'SHA-1'`
14811cb0ef41Sopenharmony_ci* `'SHA-256'`
14821cb0ef41Sopenharmony_ci* `'SHA-384'`
14831cb0ef41Sopenharmony_ci* `'SHA-512'`
14841cb0ef41Sopenharmony_ci
14851cb0ef41Sopenharmony_ciIf represented as an {Object}, the object must have a `name` property
14861cb0ef41Sopenharmony_ciwhose value is one of the above listed values.
14871cb0ef41Sopenharmony_ci
14881cb0ef41Sopenharmony_ci#### `rsaHashedImportParams.name`
14891cb0ef41Sopenharmony_ci
14901cb0ef41Sopenharmony_ci<!-- YAML
14911cb0ef41Sopenharmony_ciadded: v15.0.0
14921cb0ef41Sopenharmony_ci-->
14931cb0ef41Sopenharmony_ci
14941cb0ef41Sopenharmony_ci* Type: {string} Must be one of `'RSASSA-PKCS1-v1_5'`, `'RSA-PSS'`, or
14951cb0ef41Sopenharmony_ci  `'RSA-OAEP'`.
14961cb0ef41Sopenharmony_ci
14971cb0ef41Sopenharmony_ci### Class: `RsaHashedKeyGenParams`
14981cb0ef41Sopenharmony_ci
14991cb0ef41Sopenharmony_ci<!-- YAML
15001cb0ef41Sopenharmony_ciadded: v15.0.0
15011cb0ef41Sopenharmony_ci-->
15021cb0ef41Sopenharmony_ci
15031cb0ef41Sopenharmony_ci#### `rsaHashedKeyGenParams.hash`
15041cb0ef41Sopenharmony_ci
15051cb0ef41Sopenharmony_ci<!-- YAML
15061cb0ef41Sopenharmony_ciadded: v15.0.0
15071cb0ef41Sopenharmony_ci-->
15081cb0ef41Sopenharmony_ci
15091cb0ef41Sopenharmony_ci* Type: {string|Object}
15101cb0ef41Sopenharmony_ci
15111cb0ef41Sopenharmony_ciIf represented as a {string}, the value must be one of:
15121cb0ef41Sopenharmony_ci
15131cb0ef41Sopenharmony_ci* `'SHA-1'`
15141cb0ef41Sopenharmony_ci* `'SHA-256'`
15151cb0ef41Sopenharmony_ci* `'SHA-384'`
15161cb0ef41Sopenharmony_ci* `'SHA-512'`
15171cb0ef41Sopenharmony_ci
15181cb0ef41Sopenharmony_ciIf represented as an {Object}, the object must have a `name` property
15191cb0ef41Sopenharmony_ciwhose value is one of the above listed values.
15201cb0ef41Sopenharmony_ci
15211cb0ef41Sopenharmony_ci#### `rsaHashedKeyGenParams.modulusLength`
15221cb0ef41Sopenharmony_ci
15231cb0ef41Sopenharmony_ci<!-- YAML
15241cb0ef41Sopenharmony_ciadded: v15.0.0
15251cb0ef41Sopenharmony_ci-->
15261cb0ef41Sopenharmony_ci
15271cb0ef41Sopenharmony_ci* Type: {number}
15281cb0ef41Sopenharmony_ci
15291cb0ef41Sopenharmony_ciThe length in bits of the RSA modulus. As a best practice, this should be
15301cb0ef41Sopenharmony_ciat least `2048`.
15311cb0ef41Sopenharmony_ci
15321cb0ef41Sopenharmony_ci#### `rsaHashedKeyGenParams.name`
15331cb0ef41Sopenharmony_ci
15341cb0ef41Sopenharmony_ci<!-- YAML
15351cb0ef41Sopenharmony_ciadded: v15.0.0
15361cb0ef41Sopenharmony_ci-->
15371cb0ef41Sopenharmony_ci
15381cb0ef41Sopenharmony_ci* Type: {string} Must be one of `'RSASSA-PKCS1-v1_5'`, `'RSA-PSS'`, or
15391cb0ef41Sopenharmony_ci  `'RSA-OAEP'`.
15401cb0ef41Sopenharmony_ci
15411cb0ef41Sopenharmony_ci#### `rsaHashedKeyGenParams.publicExponent`
15421cb0ef41Sopenharmony_ci
15431cb0ef41Sopenharmony_ci<!-- YAML
15441cb0ef41Sopenharmony_ciadded: v15.0.0
15451cb0ef41Sopenharmony_ci-->
15461cb0ef41Sopenharmony_ci
15471cb0ef41Sopenharmony_ci* Type: {Uint8Array}
15481cb0ef41Sopenharmony_ci
15491cb0ef41Sopenharmony_ciThe RSA public exponent. This must be a {Uint8Array} containing a big-endian,
15501cb0ef41Sopenharmony_ciunsigned integer that must fit within 32-bits. The {Uint8Array} may contain an
15511cb0ef41Sopenharmony_ciarbitrary number of leading zero-bits. The value must be a prime number. Unless
15521cb0ef41Sopenharmony_cithere is reason to use a different value, use `new Uint8Array([1, 0, 1])`
15531cb0ef41Sopenharmony_ci(65537) as the public exponent.
15541cb0ef41Sopenharmony_ci
15551cb0ef41Sopenharmony_ci### Class: `RsaOaepParams`
15561cb0ef41Sopenharmony_ci
15571cb0ef41Sopenharmony_ci<!-- YAML
15581cb0ef41Sopenharmony_ciadded: v15.0.0
15591cb0ef41Sopenharmony_ci-->
15601cb0ef41Sopenharmony_ci
15611cb0ef41Sopenharmony_ci#### `rsaOaepParams.label`
15621cb0ef41Sopenharmony_ci
15631cb0ef41Sopenharmony_ci<!-- YAML
15641cb0ef41Sopenharmony_ciadded: v15.0.0
15651cb0ef41Sopenharmony_ci-->
15661cb0ef41Sopenharmony_ci
15671cb0ef41Sopenharmony_ci* Type: {ArrayBuffer|TypedArray|DataView|Buffer}
15681cb0ef41Sopenharmony_ci
15691cb0ef41Sopenharmony_ciAn additional collection of bytes that will not be encrypted, but will be bound
15701cb0ef41Sopenharmony_cito the generated ciphertext.
15711cb0ef41Sopenharmony_ci
15721cb0ef41Sopenharmony_ciThe `rsaOaepParams.label` parameter is optional.
15731cb0ef41Sopenharmony_ci
15741cb0ef41Sopenharmony_ci#### `rsaOaepParams.name`
15751cb0ef41Sopenharmony_ci
15761cb0ef41Sopenharmony_ci<!-- YAML
15771cb0ef41Sopenharmony_ciadded: v15.0.0
15781cb0ef41Sopenharmony_ci-->
15791cb0ef41Sopenharmony_ci
15801cb0ef41Sopenharmony_ci* Type: {string} must be `'RSA-OAEP'`.
15811cb0ef41Sopenharmony_ci
15821cb0ef41Sopenharmony_ci### Class: `RsaPssParams`
15831cb0ef41Sopenharmony_ci
15841cb0ef41Sopenharmony_ci<!-- YAML
15851cb0ef41Sopenharmony_ciadded: v15.0.0
15861cb0ef41Sopenharmony_ci-->
15871cb0ef41Sopenharmony_ci
15881cb0ef41Sopenharmony_ci#### `rsaPssParams.name`
15891cb0ef41Sopenharmony_ci
15901cb0ef41Sopenharmony_ci<!-- YAML
15911cb0ef41Sopenharmony_ciadded: v15.0.0
15921cb0ef41Sopenharmony_ci-->
15931cb0ef41Sopenharmony_ci
15941cb0ef41Sopenharmony_ci* Type: {string} Must be `'RSA-PSS'`.
15951cb0ef41Sopenharmony_ci
15961cb0ef41Sopenharmony_ci#### `rsaPssParams.saltLength`
15971cb0ef41Sopenharmony_ci
15981cb0ef41Sopenharmony_ci<!-- YAML
15991cb0ef41Sopenharmony_ciadded: v15.0.0
16001cb0ef41Sopenharmony_ci-->
16011cb0ef41Sopenharmony_ci
16021cb0ef41Sopenharmony_ci* Type: {number}
16031cb0ef41Sopenharmony_ci
16041cb0ef41Sopenharmony_ciThe length (in bytes) of the random salt to use.
16051cb0ef41Sopenharmony_ci
16061cb0ef41Sopenharmony_ci[^1]: An experimental implementation of
16071cb0ef41Sopenharmony_ci    [Secure Curves in the Web Cryptography API][] as of 05 May 2022
16081cb0ef41Sopenharmony_ci
16091cb0ef41Sopenharmony_ci[JSON Web Key]: https://tools.ietf.org/html/rfc7517
16101cb0ef41Sopenharmony_ci[Key usages]: #cryptokeyusages
16111cb0ef41Sopenharmony_ci[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
16121cb0ef41Sopenharmony_ci[RFC 4122]: https://www.rfc-editor.org/rfc/rfc4122.txt
16131cb0ef41Sopenharmony_ci[Secure Curves in the Web Cryptography API]: https://wicg.github.io/webcrypto-secure-curves/
16141cb0ef41Sopenharmony_ci[Web Crypto API]: https://www.w3.org/TR/WebCryptoAPI/
1615