crypto: expose KeyObject class

PR-URL: https://github.com/nodejs/node/pull/26438
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
Filip Skokan 2019-03-11 21:26:22 +01:00 committed by Tobias Nießen
parent 6913bd183b
commit f1056542f0
No known key found for this signature in database
GPG Key ID: 718207F8FD156B70
3 changed files with 14 additions and 7 deletions

View File

@ -1109,14 +1109,18 @@ This can be called many times with new data as it is streamed.
## Class: KeyObject ## Class: KeyObject
<!-- YAML <!-- YAML
added: v11.6.0 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 Node.js uses a `KeyObject` class to represent a symmetric or asymmetric key,
directly. Instead, factory functions exist to create instances of this class and each kind of key exposes different functions. The
in a secure manner, see [`crypto.createSecretKey()`][], [`crypto.createSecretKey()`][], [`crypto.createPublicKey()`][] and
[`crypto.createPublicKey()`][] and [`crypto.createPrivateKey()`][]. A [`crypto.createPrivateKey()`][] methods are used to create `KeyObject`
`KeyObject` can represent a symmetric or asymmetric key, and each kind of key instances. `KeyObject` objects are not to be created directly using the `new`
exposes different functions. keyword.
Most applications should consider using the new `KeyObject` API instead of Most applications should consider using the new `KeyObject` API instead of
passing keys as strings or `Buffer`s due to improved security features. passing keys as strings or `Buffer`s due to improved security features.

View File

@ -60,7 +60,8 @@ const {
const { const {
createSecretKey, createSecretKey,
createPublicKey, createPublicKey,
createPrivateKey createPrivateKey,
KeyObject,
} = require('internal/crypto/keys'); } = require('internal/crypto/keys');
const { const {
DiffieHellman, DiffieHellman,
@ -191,6 +192,7 @@ module.exports = exports = {
ECDH, ECDH,
Hash, Hash,
Hmac, Hmac,
KeyObject,
Sign, Sign,
Verify Verify
}; };

View File

@ -333,6 +333,7 @@ module.exports = {
createSecretKey, createSecretKey,
createPublicKey, createPublicKey,
createPrivateKey, createPrivateKey,
KeyObject,
// These are designed for internal use only and should not be exposed. // These are designed for internal use only and should not be exposed.
parsePublicKeyEncoding, parsePublicKeyEncoding,