crypto.publicEncrypt(key, buffer)


使用 keybuffer 的内容进行加密,并返回一个包含加密内容的新 Buffer。返回的数据可以使用相应的私钥解密,例如使用 crypto.privateDecrypt()

【Encrypts the content of buffer with key and returns a new Buffer with encrypted content. The returned data can be decrypted using the corresponding private key, for example using crypto.privateDecrypt().】

如果 key 不是 KeyObject,此函数的行为就好像将 key 传递给了 crypto.createPublicKey()。如果它是一个对象,则可以传递 padding 属性。否则,此函数使用 RSA_PKCS1_OAEP_PADDING

【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_OAEP_PADDING.】

由于 RSA 公钥可以由私钥推导出,因此可以传递私钥而不是公钥。

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