Rivest-Shamir-Adleman

Algorithm used for Asymmetric cryptography.

  • Public key = (n,e) where n= large modulus and e= encrypting exponent
  • Private key= (n,d) where n=large modulus and d= decrypting exponent

Key generation

  1. Calculate nn n=p×qn = p \times q

    • Where pp and qq are large prime numbers.
    • pp and qq are kept secret.
    • nn is public.
  2. Choose ee

    • ee is a randomly chosen number (preferably prime).
    • Most common values: 33 and 6553765537.
    • Reason: They can be efficiently used for modular exponentiation.
    • Note: 3 is not considered safe.
    • ee is public.
  3. Calculate ϕ(n)\phi(n) ϕ(n)=(p−1)×(q−1)\phi(n) = (p-1) \times (q-1)

  4. Calculate dd e×d≡1(modϕ(n))e \times d \equiv 1 \pmod{\phi(n)}

    • dd is private.

Security Note: It is computationally infeasible to calculate dd from nn because pp and qq are secret and it is very difficult to derive them from nn.


Encryption

Formula: C=Me(modn)C = M^e \pmod n

  • CC: Cipher text
  • MM: Unencrypted message

Process:

  • Modular Exponentiation: This is performed to encrypt MM. This method is used because when MM and ee are large, calculating MeM^e directly becomes exponentially (impossibly) large.
  • Padding: Padding is done to add randomness to the data.

Note

The encrypted message for the same plaintext will nearly always be different. To avoid same output on every encryption, secure implementations of RSA always use a process called padding before the message is encrypted



Decryption

Formula: M=Cd(modn)M = C^d \pmod n


Representation of keys

Public or private keys can be stored and transferred in different ways. Two of them include -

  1. Private Enhanced Mail (PEM)
  2. JSON Web Key (JWK)

Designed and Developed by Shaurya Mehta. Built with Quartz.