From bd5e12764c46f0b754942e471924156df113bd2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Tue, 25 Dec 2018 13:13:52 +0100 Subject: [PATCH 1/4] crypto: always accept private keys as public keys Some APIs already accept private keys instead of public keys. This changes all relevant crypto APIs to do so. --- doc/api/crypto.md | 17 +++++++++++++++++ lib/internal/crypto/keys.js | 7 +------ lib/internal/crypto/sig.js | 9 +++++---- src/node_crypto.cc | 28 ++-------------------------- test/parallel/test-crypto-keygen.js | 16 ++++++++++------ 5 files changed, 35 insertions(+), 42 deletions(-) diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 2ba721d062296f..75f05f1fac7019 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -1369,6 +1369,9 @@ This can be called many times with new data as it is streamed. * `key` {Object | string | Buffer} - `key`: {string | Buffer} @@ -1833,6 +1844,12 @@ must be an object with the properties described above. If the format is `'pem'`, the `'key'` may also be an X.509 certificate. +Because public keys can be derived from private keys, a private key may be +passed instead of a public key. In that case, this function behaves as if +[`crypto.createPrivateKey()`][] had been called, except that the type of the +returned `KeyObject` will be `public` and that the private key cannot be +extracted from the returned `KeyObject`. + ### crypto.createSecretKey(key) * `key` {Object | string | Buffer} From 6602a44ef7c124ebf7637b771146323e6ecc0eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Fri, 4 Jan 2019 00:11:44 +0100 Subject: [PATCH 3/4] fixup! crypto: always accept private keys as public keys --- doc/api/crypto.md | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 53f0f06e7e64e8..1e10c16172c179 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -1825,7 +1825,6 @@ must be an object with the properties described above. ### crypto.createPublicKey(key)