From 3cdd070fecdf21dee896a68508f81c44cdf1d557 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 8 Oct 2017 19:35:18 +0200 Subject: [PATCH] doc: public keys don't accept passphrases Since `crypto.publicDecrypt()` and `crypto.publicEncrypt()` accept both public and private keys, make it clear that the `passphrase` option only applies to private keys. Refs: https://github.com/nodejs/node/pull/16038 --- doc/api/crypto.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 8bafbfe791b231..86191d2e334bc6 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -1709,43 +1709,43 @@ Encrypts `buffer` with `privateKey`. `privateKey` can be an object or a string. If `privateKey` is a string, it is treated as the key with no passphrase and will use `RSA_PKCS1_PADDING`. -### crypto.publicDecrypt(publicKey, buffer) +### crypto.publicDecrypt(key, buffer) -- `publicKey` {Object | string} - - `key` {string} A PEM encoded public key. - - `passphrase` {string} An optional passphrase for the public key. +- `key` {Object | string} + - `key` {string} A PEM encoded public or private key. + - `passphrase` {string} An optional passphrase for the private key. - `padding` {crypto.constants} An optional padding value defined in `crypto.constants`, which may be: `crypto.constants.RSA_NO_PADDING` or `RSA_PKCS1_PADDING`. - `buffer` {Buffer | TypedArray | DataView} -Decrypts `buffer` with `publicKey`. +Decrypts `buffer` with `key`. -`publicKey` can be an object or a string. If `publicKey` is a string, it is -treated as the key with no passphrase and will use `RSA_PKCS1_PADDING`. +`key` can be an object or a string. If `key` is a string, it is treated as +the key with no passphrase and will use `RSA_PKCS1_PADDING`. Because RSA public keys can be derived from private keys, a private key may be passed instead of a public key. -### crypto.publicEncrypt(publicKey, buffer) +### crypto.publicEncrypt(key, buffer) -- `publicKey` {Object | string} - - `key` {string} A PEM encoded public key. - - `passphrase` {string} An optional passphrase for the public key. +- `key` {Object | string} + - `key` {string} A PEM encoded public or private key. + - `passphrase` {string} An optional passphrase for the private key. - `padding` {crypto.constants} An optional padding value defined in `crypto.constants`, which may be: `crypto.constants.RSA_NO_PADDING`, `RSA_PKCS1_PADDING`, or `crypto.constants.RSA_PKCS1_OAEP_PADDING`. - `buffer` {Buffer | TypedArray | DataView} -Encrypts the content of `buffer` with `publicKey` and returns a new +Encrypts the content of `buffer` with `key` and returns a new [`Buffer`][] with encrypted content. -`publicKey` can be an object or a string. If `publicKey` is a string, it is -treated as the key with no passphrase and will use `RSA_PKCS1_OAEP_PADDING`. +`key` can be an object or a string. If `key` is a string, it is treated as +the key with no passphrase and will use `RSA_PKCS1_OAEP_PADDING`. Because RSA public keys can be derived from private keys, a private key may be passed instead of a public key.