Skip to content

Commit 74c6f57

Browse files
panvatargos
authored andcommitted
crypto: expose KeyObject class
PR-URL: #26438 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent 00a6f76 commit 74c6f57

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

doc/api/crypto.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -1109,14 +1109,18 @@ This can be called many times with new data as it is streamed.
11091109
## Class: KeyObject
11101110
<!-- YAML
11111111
added: v11.6.0
1112+
changes:
1113+
- version: REPLACEME
1114+
pr-url: https://github.com/nodejs/node/pull/26438
1115+
description: This class is now exported.
11121116
-->
11131117

1114-
Node.js uses an internal `KeyObject` class which should not be accessed
1115-
directly. Instead, factory functions exist to create instances of this class
1116-
in a secure manner, see [`crypto.createSecretKey()`][],
1117-
[`crypto.createPublicKey()`][] and [`crypto.createPrivateKey()`][]. A
1118-
`KeyObject` can represent a symmetric or asymmetric key, and each kind of key
1119-
exposes different functions.
1118+
Node.js uses a `KeyObject` class to represent a symmetric or asymmetric key,
1119+
and each kind of key exposes different functions. The
1120+
[`crypto.createSecretKey()`][], [`crypto.createPublicKey()`][] and
1121+
[`crypto.createPrivateKey()`][] methods are used to create `KeyObject`
1122+
instances. `KeyObject` objects are not to be created directly using the `new`
1123+
keyword.
11201124

11211125
Most applications should consider using the new `KeyObject` API instead of
11221126
passing keys as strings or `Buffer`s due to improved security features.

lib/crypto.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ const {
6060
const {
6161
createSecretKey,
6262
createPublicKey,
63-
createPrivateKey
63+
createPrivateKey,
64+
KeyObject,
6465
} = require('internal/crypto/keys');
6566
const {
6667
DiffieHellman,
@@ -192,6 +193,7 @@ module.exports = exports = {
192193
ECDH,
193194
Hash,
194195
Hmac,
196+
KeyObject,
195197
Sign,
196198
Verify
197199
};

lib/internal/crypto/keys.js

+1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ module.exports = {
318318
createSecretKey,
319319
createPublicKey,
320320
createPrivateKey,
321+
KeyObject,
321322

322323
// These are designed for internal use only and should not be exposed.
323324
parsePublicKeyEncoding,

0 commit comments

Comments
 (0)