Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: expose KeyObject class #26438

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:/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,
sam-github marked this conversation as resolved.
Show resolved Hide resolved
} = require('internal/crypto/keys');
const {
DiffieHellman,
Expand Down Expand Up @@ -191,6 +192,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