RSA implementation
- Source:
Methods
(async, static) decrypt(m, n, e, d, p, q, u, randomPayload) → {Promise.<String>}
Decrypt RSA message
Parameters:
Name | Type | Description |
---|---|---|
m |
Uint8Array | Message |
n |
Uint8Array | RSA public modulus |
e |
Uint8Array | RSA public exponent |
d |
Uint8Array | RSA private exponent |
p |
Uint8Array | RSA private prime p |
q |
Uint8Array | RSA private prime q |
u |
Uint8Array | RSA private coefficient |
randomPayload |
Uint8Array | Data to return on decryption error, instead of throwing (needed for constant-time processing) |
- Source:
Throws:
-
on decryption error, unless
randomPayload
is given - Type
- Error
Returns:
RSA Plaintext.
- Type
- Promise.<String>
(async, static) encrypt(data, n, e) → {Promise.<Uint8Array>}
Encrypt message
Parameters:
Name | Type | Description |
---|---|---|
data |
Uint8Array | Message |
n |
Uint8Array | RSA public modulus |
e |
Uint8Array | RSA public exponent |
- Source:
Returns:
RSA Ciphertext.
- Type
- Promise.<Uint8Array>
(async, static) generate(bits, e) → {Object}
Generate a new random private key B bits long with public exponent E.
When possible, webCrypto or nodeCrypto is used. Otherwise, primes are generated using 40 rounds of the Miller-Rabin probabilistic random prime generation algorithm.
Parameters:
Name | Type | Description |
---|---|---|
bits |
Integer | RSA bit length |
e |
Integer | RSA public exponent |
- Source:
- See:
-
- module:crypto/public_key/prime
Returns:
RSA public modulus, RSA public exponent, RSA private exponent, RSA private prime p, RSA private prime q, u = p ** -1 mod q
- Type
- Object
(async, static) sign(hashAlgo, data, n, e, d, p, q, u, hashed) → {Promise.<Uint8Array>}
Create signature
Parameters:
Name | Type | Description |
---|---|---|
hashAlgo |
module:enums.hash | Hash algorithm |
data |
Uint8Array | Message |
n |
Uint8Array | RSA public modulus |
e |
Uint8Array | RSA public exponent |
d |
Uint8Array | RSA private exponent |
p |
Uint8Array | RSA private prime p |
q |
Uint8Array | RSA private prime q |
u |
Uint8Array | RSA private coefficient |
hashed |
Uint8Array | Hashed message |
- Source:
Returns:
RSA Signature.
- Type
- Promise.<Uint8Array>
(async, static) validateParams(n, e, d, p, q, u) → {Promise.<Boolean>}
Validate RSA parameters
Parameters:
Name | Type | Description |
---|---|---|
n |
Uint8Array | RSA public modulus |
e |
Uint8Array | RSA public exponent |
d |
Uint8Array | RSA private exponent |
p |
Uint8Array | RSA private prime p |
q |
Uint8Array | RSA private prime q |
u |
Uint8Array | RSA inverse of p w.r.t. q |
- Source:
Returns:
Whether params are valid.
- Type
- Promise.<Boolean>
(async, static) verify(hashAlgo, data, s, n, e, hashed) → {Boolean}
Verify signature
Parameters:
Name | Type | Description |
---|---|---|
hashAlgo |
module:enums.hash | Hash algorithm |
data |
Uint8Array | Message |
s |
Uint8Array | Signature |
n |
Uint8Array | RSA public modulus |
e |
Uint8Array | RSA public exponent |
hashed |
Uint8Array | Hashed message |
- Source:
Returns:
- Type
- Boolean
(inner) jwkToPrivate()
Convert JWK private key to OpenPGP private key params
- Source:
(async, inner) privateToJWK(hashAlgo, n, e, d, p, q, u)
Convert Openpgp private key params to jwk key according to
Parameters:
Name | Type | Description |
---|---|---|
hashAlgo |
String | |
n |
Uint8Array | |
e |
Uint8Array | |
d |
Uint8Array | |
p |
Uint8Array | |
q |
Uint8Array | |
u |
Uint8Array |
- Source:
(inner) publicToJWK(hashAlgo, n, e)
Convert Openpgp key public params to jwk key according to
Parameters:
Name | Type | Description |
---|---|---|
hashAlgo |
String | |
n |
Uint8Array | |
e |
Uint8Array |
- Source: