Module: crypto/public_key/rsa

RSA implementation

Source:

Requires

Methods

(async, static) decrypt(m, n, e, d, p, q, u) → {BN}

Decrypt RSA message

Parameters:
Name Type Description
m BN

message

n BN

RSA public modulus

e BN

RSA public exponent

d BN

RSA private exponent

p BN

RSA private prime p

q BN

RSA private prime q

u BN

RSA private inverse of prime q

Source:
Returns:

RSA Plaintext

Type
BN

(async, static) encrypt(m, n, e) → {BN}

Encrypt message

Parameters:
Name Type Description
m BN

message

n BN

RSA public modulus

e BN

RSA public exponent

Source:
Returns:

RSA Ciphertext

Type
BN

(async, static) generate(B, E) → {Object}

Generate a new random private key B bits long with public exponent E.

When possible, webCrypto is used. Otherwise, primes are generated using 40 rounds of the Miller-Rabin probabilistic random prime generation algorithm.

Parameters:
Name Type Description
B Integer

RSA bit length

E String

RSA public exponent in hex string

Source:
See:
Returns:

RSA public modulus, RSA public exponent, RSA private exponent, RSA private prime p, RSA private prime q, u = q ** -1 mod p

Type
Object

(async, static) sign(m, n, e, d) → {BN}

Create signature

Parameters:
Name Type Description
m BN

message

n BN

RSA public modulus

e BN

RSA public exponent

d BN

RSA private exponent

Source:
Returns:

RSA Signature

Type
BN

(async, static) verify(s, n, e) → {BN}

Verify signature

Parameters:
Name Type Description
s BN

signature

n BN

RSA public modulus

e BN

RSA public exponent

Source:
Returns:
Type
BN