crypto.privateEncrypt(privateKey, buffer)

  • privateKey {Object | string | Buffer | KeyObject}
    • key {string | Buffer | KeyObject} A PEM encoded private key.
    • passphrase {string | Buffer} 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 crypto.constants.RSA_PKCS1_PADDING.
  • buffer {Buffer | TypedArray | DataView}
  • Returns: {Buffer} A new Buffer with the encrypted content.

Encrypts buffer with privateKey. The returned data can be decrypted using the corresponding public key, for example using [crypto.publicDecrypt()][].

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_PADDING.


最后修改 April 16, 2020: 加密 (a75e592)