crypto: add subtle.getPublicKey() utility function in Web Cryptography · nodejs/node@6fcce90

@@ -114,6 +114,7 @@ Key Formats:

114114115115

Methods:

116116117+

* [`subtle.getPublicKey()`][]

117118

* [`SubtleCrypto.supports()`][]

118119119120

## Secure Curves in the Web Cryptography API

@@ -477,36 +478,36 @@ const decrypted = new TextDecoder().decode(await crypto.subtle.decrypt(

477478

The table details the algorithms supported by the Node.js Web Crypto API

478479

implementation and the APIs supported for each:

479480480-

| Algorithm | `generateKey` | `exportKey` | `importKey` | `encrypt` | `decrypt` | `wrapKey` | `unwrapKey` | `deriveBits` | `deriveKey` | `sign` | `verify` | `digest` |

481-

| ---------------------------- | ------------- | ----------- | ----------- | --------- | --------- | --------- | ----------- | ------------ | ----------- | ------ | -------- | -------- |

482-

| `'AES-CBC'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | |

483-

| `'AES-CTR'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | |

484-

| `'AES-GCM'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | |

485-

| `'AES-KW'` | ✔ | ✔ | ✔ | | | ✔ | ✔ | | | | | |

486-

| `'cSHAKE128'`[^modern-algos] | | | | | | | | | | | | ✔ |

487-

| `'cSHAKE256'`[^modern-algos] | | | | | | | | | | | | ✔ |

488-

| `'ECDH'` | ✔ | ✔ | ✔ | | | | | ✔ | ✔ | | | |

489-

| `'ECDSA'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |

490-

| `'Ed25519'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |

491-

| `'Ed448'`[^secure-curves] | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |

492-

| `'HKDF'` | | ✔ | ✔ | | | | | ✔ | ✔ | | | |

493-

| `'HMAC'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |

494-

| `'ML-DSA-44'`[^modern-algos] | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |

495-

| `'ML-DSA-65'`[^modern-algos] | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |

496-

| `'ML-DSA-87'`[^modern-algos] | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |

497-

| `'PBKDF2'` | | ✔ | ✔ | | | | | ✔ | ✔ | | | |

498-

| `'RSA-OAEP'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | |

499-

| `'RSA-PSS'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |

500-

| `'RSASSA-PKCS1-v1_5'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |

501-

| `'SHA-1'` | | | | | | | | | | | | ✔ |

502-

| `'SHA-256'` | | | | | | | | | | | | ✔ |

503-

| `'SHA-384'` | | | | | | | | | | | | ✔ |

504-

| `'SHA-512'` | | | | | | | | | | | | ✔ |

505-

| `'SHA3-256'`[^modern-algos] | | | | | | | | | | | | ✔ |

506-

| `'SHA3-384'`[^modern-algos] | | | | | | | | | | | | ✔ |

507-

| `'SHA3-512'`[^modern-algos] | | | | | | | | | | | | ✔ |

508-

| `'X25519'` | ✔ | ✔ | ✔ | | | | | ✔ | ✔ | | | |

509-

| `'X448'`[^secure-curves] | ✔ | ✔ | ✔ | | | | | ✔ | ✔ | | | |

481+

| Algorithm | `generateKey` | `exportKey` | `importKey` | `encrypt` | `decrypt` | `wrapKey` | `unwrapKey` | `deriveBits` | `deriveKey` | `sign` | `verify` | `digest` | `getPublicKey` |

482+

| ---------------------------- | ------------- | ----------- | ----------- | --------- | --------- | --------- | ----------- | ------------ | ----------- | ------ | -------- | -------- | -------------- |

483+

| `'AES-CBC'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | | |

484+

| `'AES-CTR'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | | |

485+

| `'AES-GCM'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | | |

486+

| `'AES-KW'` | ✔ | ✔ | ✔ | | | ✔ | ✔ | | | | | | |

487+

| `'cSHAKE128'`[^modern-algos] | | | | | | | | | | | | ✔ | |

488+

| `'cSHAKE256'`[^modern-algos] | | | | | | | | | | | | ✔ | |

489+

| `'ECDH'` | ✔ | ✔ | ✔ | | | | | ✔ | ✔ | | | | ✔ |

490+

| `'ECDSA'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | | ✔ |

491+

| `'Ed25519'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | | ✔ |

492+

| `'Ed448'`[^secure-curves] | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | | ✔ |

493+

| `'HKDF'` | | ✔ | ✔ | | | | | ✔ | ✔ | | | | |

494+

| `'HMAC'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | | |

495+

| `'ML-DSA-44'`[^modern-algos] | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | | ✔ |

496+

| `'ML-DSA-65'`[^modern-algos] | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | | ✔ |

497+

| `'ML-DSA-87'`[^modern-algos] | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | | ✔ |

498+

| `'PBKDF2'` | | ✔ | ✔ | | | | | ✔ | ✔ | | | | |

499+

| `'RSA-OAEP'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | | ✔ |

500+

| `'RSA-PSS'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | | ✔ |

501+

| `'RSASSA-PKCS1-v1_5'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | | ✔ |

502+

| `'SHA-1'` | | | | | | | | | | | | ✔ | |

503+

| `'SHA-256'` | | | | | | | | | | | | ✔ | |

504+

| `'SHA-384'` | | | | | | | | | | | | ✔ | |

505+

| `'SHA-512'` | | | | | | | | | | | | ✔ | |

506+

| `'SHA3-256'`[^modern-algos] | | | | | | | | | | | | ✔ | |

507+

| `'SHA3-384'`[^modern-algos] | | | | | | | | | | | | ✔ | |

508+

| `'SHA3-512'`[^modern-algos] | | | | | | | | | | | | ✔ | |

509+

| `'X25519'` | ✔ | ✔ | ✔ | | | | | ✔ | ✔ | | | | ✔ |

510+

| `'X448'`[^secure-curves] | ✔ | ✔ | ✔ | | | | | ✔ | ✔ | | | | ✔ |

510511511512

## Class: `Crypto`

512513

@@ -691,7 +692,7 @@ added: REPLACEME

691692692693

<!--lint disable maximum-line-length remark-lint-->

693694694-

* `operation` {string} "encrypt", "decrypt", "sign", "verify", "digest", "generateKey", "deriveKey", "deriveBits", "importKey", "exportKey", "wrapKey", or "unwrapKey"

695+

* `operation` {string} "encrypt", "decrypt", "sign", "verify", "digest", "generateKey", "deriveKey", "deriveBits", "importKey", "exportKey", "getPublicKey", "wrapKey", or "unwrapKey"

695696

* `algorithm` {string|Algorithm}

696697

* `lengthOrAdditionalAlgorithm` {null|number|string|Algorithm|undefined} 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", or the algorithm of key to be imported after unwrapping when operation is "unwrapKey". **Default:** `null` when operation is "deriveBits", `undefined` otherwise.

697698

* Returns: {boolean} Indicating whether the implementation supports the given operation

@@ -925,6 +926,20 @@ specification.

925926

| `'RSA-PSS'` | ✔ | ✔ | ✔ | | | | |

926927

| `'RSASSA-PKCS1-v1_5'` | ✔ | ✔ | ✔ | | | | |

927928929+

### `subtle.getPublicKey(key, keyUsages)`

930+931+

<!-- YAML

932+

added: REPLACEME

933+

-->

934+935+

> Stability: 1.1 - Active development

936+937+

* `key` {CryptoKey} A private key from which to derive the corresponding public key.

938+

* `keyUsages` {string\[]} See [Key usages][].

939+

* Returns: {Promise} Fulfills with a {CryptoKey} upon success.

940+941+

Derives the public key from a given private key.

942+928943

### `subtle.generateKey(algorithm, extractable, keyUsages)`

929944930945

<!-- YAML

@@ -2142,3 +2157,4 @@ The length (in bytes) of the random salt to use.

21422157

[Secure Curves in the Web Cryptography API]: #secure-curves-in-the-web-cryptography-api

21432158

[Web Crypto API]: https://www.w3.org/TR/WebCryptoAPI/

21442159

[`SubtleCrypto.supports()`]: #static-method-subtlecryptosupportsoperation-algorithm-lengthoradditionalalgorithm

2160+

[`subtle.getPublicKey()`]: #subtlegetpublickeykey-keyusages