RSA is a cryptography algorithm used for asymmetric encryption and signing. It is based on the practical difficulty of factoring the product of two large prime numbers. The algorithm for generating keys looks like below.
- Pick two large prime numbers (large prime numbers are difficult to factor out once we multiple them together). Let us call them and .
- Let us compute
N
called the module by multiplying and $qN=p \times q$$ - Compute Euler’s totient function
- Choose an integer such that and
- Compute as the modular multiplicative inverse of , i.e.,
- The public key is
- The private key is
Encryption
To encrypt a given data into ciphertext we use the following equation.
Decryption
To decrypt ciphertext c into plaintext