crypto.publicDecrypt(key, buffer)
key
<Object> | <string> | <Buffer> | <KeyObject>passphrase
<string> | <Buffer> 可选的私钥密码。padding
<crypto.constants>crypto.constants
中定义的可选填充值,可以是:crypto.constants.RSA_NO_PADDING
或crypto.constants.RSA_PKCS1_PADDING
。
buffer
<Buffer> | <TypedArray> | <DataView>- 返回: <Buffer> 带有解密内容的新
Buffer
。
使用 key
.buffer
解密 buffer
之前使用相应的私钥加密,例如使用 crypto.privateEncrypt()
。
如果 key
不是 KeyObject
,则此函数的行为就像将 key
传给 crypto.createPublicKey()
一样。
如果是对象,则可以传入 padding
属性。
否则,该函数使用 RSA_PKCS1_PADDING
。
由于 RSA 公钥可以从私钥派生,因此可以传入私钥而不是公钥。
key
<Object> | <string> | <Buffer> | <KeyObject>passphrase
<string> | <Buffer> An optional passphrase for the private key.padding
<crypto.constants> An optional padding value defined incrypto.constants
, which may be:crypto.constants.RSA_NO_PADDING
orcrypto.constants.RSA_PKCS1_PADDING
.
buffer
<Buffer> | <TypedArray> | <DataView>- Returns: <Buffer> A new
Buffer
with the decrypted content.
Decrypts buffer
with key
.buffer
was previously encrypted using
the corresponding private key, for example using crypto.privateEncrypt()
.
If key
is not a KeyObject
, this function behaves as if
key
had been passed to crypto.createPublicKey()
. If it is an
object, the padding
property can be passed. Otherwise, this function uses
RSA_PKCS1_PADDING
.
Because RSA public keys can be derived from private keys, a private key may be passed instead of a public key.