Skip to content

Commit 3469eb9

Browse files
bnoordhuisjasnell
authored andcommitted
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. PR-URL: #16087 Ref: #16038 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 3e14449 commit 3469eb9

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

doc/api/crypto.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -1712,45 +1712,45 @@ Encrypts `buffer` with `privateKey`.
17121712
`privateKey` can be an object or a string. If `privateKey` is a string, it is
17131713
treated as the key with no passphrase and will use `RSA_PKCS1_PADDING`.
17141714

1715-
### crypto.publicDecrypt(publicKey, buffer)
1715+
### crypto.publicDecrypt(key, buffer)
17161716
<!-- YAML
17171717
added: v1.1.0
17181718
-->
1719-
- `publicKey` {Object | string}
1720-
- `key` {string} A PEM encoded public key.
1721-
- `passphrase` {string} An optional passphrase for the public key.
1719+
- `key` {Object | string}
1720+
- `key` {string} A PEM encoded public or private key.
1721+
- `passphrase` {string} An optional passphrase for the private key.
17221722
- `padding` {crypto.constants} An optional padding value defined in
17231723
`crypto.constants`, which may be: `crypto.constants.RSA_NO_PADDING` or
17241724
`RSA_PKCS1_PADDING`.
17251725
- `buffer` {Buffer | TypedArray | DataView}
17261726
- Returns: {Buffer} A new `Buffer` with the decrypted content.
17271727

1728-
Decrypts `buffer` with `publicKey`.
1728+
Decrypts `buffer` with `key`.
17291729

1730-
`publicKey` can be an object or a string. If `publicKey` is a string, it is
1731-
treated as the key with no passphrase and will use `RSA_PKCS1_PADDING`.
1730+
`key` can be an object or a string. If `key` is a string, it is treated as
1731+
the key with no passphrase and will use `RSA_PKCS1_PADDING`.
17321732

17331733
Because RSA public keys can be derived from private keys, a private key may
17341734
be passed instead of a public key.
17351735

1736-
### crypto.publicEncrypt(publicKey, buffer)
1736+
### crypto.publicEncrypt(key, buffer)
17371737
<!-- YAML
17381738
added: v0.11.14
17391739
-->
1740-
- `publicKey` {Object | string}
1741-
- `key` {string} A PEM encoded public key.
1742-
- `passphrase` {string} An optional passphrase for the public key.
1740+
- `key` {Object | string}
1741+
- `key` {string} A PEM encoded public or private key.
1742+
- `passphrase` {string} An optional passphrase for the private key.
17431743
- `padding` {crypto.constants} An optional padding value defined in
17441744
`crypto.constants`, which may be: `crypto.constants.RSA_NO_PADDING`,
17451745
`RSA_PKCS1_PADDING`, or `crypto.constants.RSA_PKCS1_OAEP_PADDING`.
17461746
- `buffer` {Buffer | TypedArray | DataView}
17471747
- Returns: {Buffer} A new `Buffer` with the encrypted content.
17481748

1749-
Encrypts the content of `buffer` with `publicKey` and returns a new
1749+
Encrypts the content of `buffer` with `key` and returns a new
17501750
[`Buffer`][] with encrypted content.
17511751

1752-
`publicKey` can be an object or a string. If `publicKey` is a string, it is
1753-
treated as the key with no passphrase and will use `RSA_PKCS1_OAEP_PADDING`.
1752+
`key` can be an object or a string. If `key` is a string, it is treated as
1753+
the key with no passphrase and will use `RSA_PKCS1_OAEP_PADDING`.
17541754

17551755
Because RSA public keys can be derived from private keys, a private key may
17561756
be passed instead of a public key.

0 commit comments

Comments
 (0)