nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.56k stars 29.05k forks source link

Do crypto.privateDecrypt and crypto.publicDecrypt parameter missing some key to js object? #54763

Closed dice36D closed 1 day ago

dice36D commented 1 week ago

Affected URL(s)

https://nodejs.org/docs/latest-v14.x/api/crypto.html#crypto_crypto_publicdecrypt_key_buffer, https://nodejs.org/docs/latest-v14.x/api/crypto.html#crypto_crypto_privatedecrypt_privatekey_buffer, https://nodejs.org/docs/latest-v18.x/api/crypto.html#cryptoprivatedecryptprivatekey-buffer

Description of the problem

I only read version 14 and version 18 document, and I found that

Screenshot 2024-09-04 at 9 00 47 PM

With APIs: crypto.privateEncrypt and crypto.publicEncrypt, the privateKey object is described with following keys: "key", "passphrase", "padding" the public key object is describe with following keys: "key", "oaepHash", "oaepLabel", "passphrase", "padding"

But to crypto.privateDecrypt and crypto.publicDecrypt, the key objects are not contain "key" (show as in capture). Can we set "key" in a JS object or not?

RedYetiDev commented 1 week ago

@nodejs/crypto

RedYetiDev commented 1 week ago

But to crypto.privateDecrypt and crypto.publicDecrypt, the key objects are not contain "key" (show as in capture).

According to the documentation, they can contain key.

If privateKey is not a KeyObject, this function behaves as if privateKey had been passed to crypto.createPrivateKey(). If it is an object, the padding property can be passed. Otherwise, this function uses RSA_PKCS1_OAEP_PADDING.

As shown below, crypto.createPrivateKey() accepts a key object property:

Screenshot 2024-09-04 at 11 20 31 AM
panva commented 1 day ago

@RedYetiDev summarized it correctly.