From 18666924936aa6fa667754f158904e606efcd4b5 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sun, 6 Oct 2024 20:09:02 +0200 Subject: [PATCH] crypto: add KeyObject.prototype.toCryptoKey MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/55262 Reviewed-By: James M Snell Reviewed-By: Yagiz Nizipli Reviewed-By: Tobias Nießen --- doc/api/crypto.md | 19 ++ lib/internal/crypto/aes.js | 7 +- lib/internal/crypto/cfrg.js | 7 +- lib/internal/crypto/ec.js | 7 +- lib/internal/crypto/keys.js | 159 +++++++++++++++ lib/internal/crypto/mac.js | 20 +- lib/internal/crypto/rsa.js | 7 +- lib/internal/crypto/webcrypto.js | 61 +----- .../test-crypto-key-objects-to-crypto-key.js | 182 ++++++++++++++++++ test/parallel/test-webcrypto-export-import.js | 5 + 10 files changed, 415 insertions(+), 59 deletions(-) create mode 100644 test/parallel/test-crypto-key-objects-to-crypto-key.js diff --git a/doc/api/crypto.md b/doc/api/crypto.md index f925d4318d3275..f141f9235df3aa 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -2136,6 +2136,24 @@ added: v11.6.0 For secret keys, this property represents the size of the key in bytes. This property is `undefined` for asymmetric keys. +### `keyObject.toCryptoKey(algorithm, extractable, keyUsages)` + + + + + +* `algorithm`: {AlgorithmIdentifier|RsaHashedImportParams|EcKeyImportParams|HmacImportParams} + + + +* `extractable`: {boolean} +* `keyUsages`: {string\[]} See [Key usages][]. +* Returns: {CryptoKey} + +Converts a `KeyObject` instance to a `CryptoKey`. + ### `keyObject.type`