diff options
author | Tobias Nießen <tniessen@tnie.de> | 2018-09-20 19:53:44 +0200 |
---|---|---|
committer | Tobias Nießen <tniessen@tnie.de> | 2018-12-24 14:50:16 +0100 |
commit | 823d86c47ce15fba8875fcebd412593b02aab362 (patch) | |
tree | a023dac2cbda38b6e194c7324e501e4054715af5 /lib/crypto.js | |
parent | 5570df407aae1e329955b1093e0e5b8bde270213 (diff) | |
download | node-new-823d86c47ce15fba8875fcebd412593b02aab362.tar.gz |
crypto: add key object API
This commit makes multiple important changes:
1. A new key object API is introduced. The KeyObject class itself is
not exposed to users, instead, several new APIs can be used to
construct key objects: createSecretKey, createPrivateKey and
createPublicKey. The new API also allows to convert between
different key formats, and even though the API itself is not
compatible to the WebCrypto standard in any way, it makes
interoperability much simpler.
2. Key objects can be used instead of the raw key material in all
relevant crypto APIs.
3. The handling of asymmetric keys has been unified and greatly
improved. Node.js now fully supports both PEM-encoded and
DER-encoded public and private keys.
4. Conversions between buffers and strings have been moved to native
code for sensitive data such as symmetric keys due to security
considerations such as zeroing temporary buffers.
5. For compatibility with older versions of the crypto API, this
change allows to specify Buffers and strings as the "passphrase"
option when reading or writing an encoded key. Note that this
can result in unexpected behavior if the password contains a
null byte.
PR-URL: https://github.com/nodejs/node/pull/24234
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/crypto.js')
-rw-r--r-- | lib/crypto.js | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/crypto.js b/lib/crypto.js index 4707ab2b35..a0062a3d53 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -60,6 +60,11 @@ const { generateKeyPairSync } = require('internal/crypto/keygen'); const { + createSecretKey, + createPublicKey, + createPrivateKey +} = require('internal/crypto/keys'); +const { DiffieHellman, DiffieHellmanGroup, ECDH @@ -149,6 +154,9 @@ module.exports = exports = { createECDH, createHash, createHmac, + createPrivateKey, + createPublicKey, + createSecretKey, createSign, createVerify, getCiphers, |