Skip to content

Commit

Permalink
crypto: expose KeyObject class
Browse files Browse the repository at this point in the history
PR-URL: #26438
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
  • Loading branch information
panva authored and targos committed Mar 27, 2019
1 parent 00a6f76 commit 74c6f57
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
16 changes: 10 additions & 6 deletions doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -1109,14 +1109,18 @@ This can be called many times with new data as it is streamed.
## Class: KeyObject
<!-- YAML
added: v11.6.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/26438
description: This class is now exported.
-->

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

Most applications should consider using the new `KeyObject` API instead of
passing keys as strings or `Buffer`s due to improved security features.
Expand Down
4 changes: 3 additions & 1 deletion lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ const {
const {
createSecretKey,
createPublicKey,
createPrivateKey
createPrivateKey,
KeyObject,
} = require('internal/crypto/keys');
const {
DiffieHellman,
Expand Down Expand Up @@ -192,6 +193,7 @@ module.exports = exports = {
ECDH,
Hash,
Hmac,
KeyObject,
Sign,
Verify
};
Expand Down
1 change: 1 addition & 0 deletions lib/internal/crypto/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ module.exports = {
createSecretKey,
createPublicKey,
createPrivateKey,
KeyObject,

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

0 comments on commit 74c6f57

Please sign in to comment.