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
<!-- 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.

View File

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

View File

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