From 760f126adb010e1e82489dc94fd7eb87613fbe9a Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Wed, 3 Feb 2021 11:08:23 +0100 Subject: [PATCH] doc: mark Certificate methods as static, add missing KeyObject.from MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/37198 Reviewed-By: James M Snell Reviewed-By: Tobias Nießen --- doc/api/crypto.md | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 9088b78babdadb..dfe49afa497781 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -53,7 +53,7 @@ The `crypto` module provides the `Certificate` class for working with SPKAC data. The most common usage is handling output generated by the HTML5 `` element. Node.js uses [OpenSSL's SPKAC implementation][] internally. -### `Certificate.exportChallenge(spkac[, encoding])` +### Static method: `Certificate.exportChallenge(spkac[, encoding])` + +* `key` {CryptoKey} +* Returns: {KeyObject} + +Example: Converting a `CryptoKey` instance to a `KeyObject`: + +```js +const { webcrypto: { subtle }, KeyObject } = require('crypto'); + +(async function() { + const key = await subtle.generateKey({ + name: 'HMAC', + hash: 'SHA-256', + length: 256 + }, true, ['sign', 'verify']); + + const keyObject = KeyObject.from(key); + console.log(keyObject.symmetricKeySize); + // Prints: 32 (symmetric key size in bytes) +})(); +``` + ### `keyObject.asymmetricKeyDetails`