Skip to content
James ZHANG edited this page Jan 16, 2022 · 5 revisions

Classes

Rsa

Provides some methods for the RSA sha256WithRSAEncryption with RSA_PKCS1_OAEP_PADDING.

Constants

sha1
utf8
base64
sha256WithRSAEncryption

Functions

paddingModeLimitedCheck(code)void

Rsa

Provides some methods for the RSA sha256WithRSAEncryption with RSA_PKCS1_OAEP_PADDING.

Kind: global class

Rsa.RSA_PKCS1_OAEP_PADDING

Alias of the RSA_PKCS1_OAEP_PADDING mode

Kind: static property of Rsa

Rsa.RSA_PKCS1_PADDING

Alias of the RSA_PKCS1_PADDING mode

Kind: static property of Rsa

Rsa.encrypt(plaintext, publicKey, padding) ⇒ string

Encrypts text with sha256WithRSAEncryption/RSA_PKCS1_OAEP_PADDING. Recommended Node Limits Version >= 12.9.0 (oaepHash was available), even if it works on v10.15.0.

Kind: static method of Rsa
Returns: string - Base64-encoded ciphertext.
Throws:

  • RangeError - While the padding isn't RSA_PKCS1_OAEP_PADDING nor RSA_PKCS1_PADDING.
Param Type Description
plaintext string Cleartext to encode.
publicKey string | Buffer A PEM encoded public certificate.
padding number Supporting RSA_PKCS1_OAEP_PADDING or RSA_PKCS1_PADDING, default is RSA_PKCS1_OAEP_PADDING.

Rsa.decrypt(ciphertext, privateKey, padding) ⇒ string

Decrypts base64 encoded string with privateKey. Recommended Node Limits Version >= 12.9.0 (oaepHash was available), even if it works on v10.15.0.

Kind: static method of Rsa
Returns: string - Utf-8 plaintext.
Throws:

  • RangeError - While the padding isn't RSA_PKCS1_OAEP_PADDING nor RSA_PKCS1_PADDING.
Param Type Description
ciphertext string Was previously encrypted string using the corresponding public certificate.
privateKey string | Buffer A PEM encoded private key certificate.
padding number Supporting RSA_PKCS1_OAEP_PADDING or RSA_PKCS1_PADDING, default is RSA_PKCS1_OAEP_PADDING.

Rsa.sign(message, privateKey) ⇒ string

Creates and returns a Sign string that uses sha256WithRSAEncryption.

Kind: static method of Rsa
Returns: string - Base64-encoded signature.

Param Type Description
message string | Buffer Content will be crypto.Sign.
privateKey string | Buffer A PEM encoded private key certificate.

Rsa.verify(message, signature, publicKey) ⇒ boolean

Verifying the message with given signature string that uses sha256WithRSAEncryption.

Kind: static method of Rsa
Returns: boolean - True is passed, false is failed.

Param Type Description
message string | Buffer Content will be crypto.Verify.
signature string The base64-encoded ciphertext.
publicKey string | Buffer A PEM encoded public certificate.

sha1

Kind: global constant

utf8

Kind: global constant

base64

Kind: global constant

sha256WithRSAEncryption

Kind: global constant

paddingModeLimitedCheck(code) ⇒ void

Kind: global function
Throws:

  • RangeError - While the padding isn't RSA_PKCS1_OAEP_PADDING nor RSA_PKCS1_PADDING.
Param Type Description
code number Supporting RSA_PKCS1_OAEP_PADDING or RSA_PKCS1_PADDING, default is RSA_PKCS1_OAEP_PADDING.