Skip to content

Commit e8286bb

Browse files
committed
doc: mark Certificate methods as static, add missing KeyObject.from
PR-URL: #37198 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent 931c2d1 commit e8286bb

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

doc/api/crypto.md

+29-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ The `crypto` module provides the `Certificate` class for working with SPKAC
5353
data. The most common usage is handling output generated by the HTML5
5454
`<keygen>` element. Node.js uses [OpenSSL's SPKAC implementation][] internally.
5555

56-
### `Certificate.exportChallenge(spkac[, encoding])`
56+
### Static method: `Certificate.exportChallenge(spkac[, encoding])`
5757
<!-- YAML
5858
added: v9.0.0
5959
changes:
@@ -76,7 +76,7 @@ console.log(challenge.toString('utf8'));
7676
// Prints: the challenge as a UTF8 string
7777
```
7878

79-
### `Certificate.exportPublicKey(spkac[, encoding])`
79+
### Static method: `Certificate.exportPublicKey(spkac[, encoding])`
8080
<!-- YAML
8181
added: v9.0.0
8282
changes:
@@ -99,7 +99,7 @@ console.log(publicKey);
9999
// Prints: the public key as <Buffer ...>
100100
```
101101

102-
### `Certificate.verifySpkac(spkac[, encoding])`
102+
### Static method: `Certificate.verifySpkac(spkac[, encoding])`
103103
<!-- YAML
104104
added: v9.0.0
105105
changes:
@@ -1284,6 +1284,32 @@ passing keys as strings or `Buffer`s due to improved security features.
12841284
The receiver obtains a cloned `KeyObject`, and the `KeyObject` does not need to
12851285
be listed in the `transferList` argument.
12861286

1287+
### Static method: `KeyObject.from(key)`
1288+
<!-- YAML
1289+
added: v15.0.0
1290+
-->
1291+
1292+
* `key` {CryptoKey}
1293+
* Returns: {KeyObject}
1294+
1295+
Example: Converting a `CryptoKey` instance to a `KeyObject`:
1296+
1297+
```js
1298+
const { webcrypto: { subtle }, KeyObject } = require('crypto');
1299+
1300+
(async function() {
1301+
const key = await subtle.generateKey({
1302+
name: 'HMAC',
1303+
hash: 'SHA-256',
1304+
length: 256
1305+
}, true, ['sign', 'verify']);
1306+
1307+
const keyObject = KeyObject.from(key);
1308+
console.log(keyObject.symmetricKeySize);
1309+
// Prints: 32 (symmetric key size in bytes)
1310+
})();
1311+
```
1312+
12871313
### `keyObject.asymmetricKeyDetails`
12881314
<!-- YAML
12891315
added: v15.7.0

0 commit comments

Comments
 (0)