RSA (Rivest–Shamir–Adleman)
To set the context clear, RSA in fact can refer not just to Asymmetric Encryption but also Digital Signature (which we would cover in later chapter). Here, we will only focus on the Encryption/Decryption protocol using RSA.
What can this protocol do?
RSA allows one party to encrypt a message with a recipient's public key, ensuring that only the recipient (who possesses the private key) can decrypt it.
Why Matters?
RSA is widely used in securing email information. When Alice wants to send her email to Bob, she makes sure that only Bob can read her email by getting Bob's public key (from a key's server or Bob's email signature). Then, she encrypts her email message with this public key, hence only the one with Bob's private key can decrypt and read this message! (Hopefully, the only one having Bob's private key is Bob)
Setup
Private Key and Public Key Generation
- Choose Two Large Prime Numbers:
Select two large primes and . Their product will define the modulus. must be large (at least 2048 bits) to ensure security.
- Calculate Euler’s Totient:
Compute
- Choose Public Exponent
Select an integer such that and gcd = 1. A common choice is , as it is efficient for encryption and verification.
- Calculate Private Exponent
Compute , the modular multiplicative inverse of modulo This satisfies: Note that this step is pretty easy due to a thing called "Extended Euclidean Algorithm" (more on this later..)
Key Pair:
-
Public Key:
-
Private Key:
Encryption
-
Represent the message as an integer such that
-
Compute the ciphertext using the recipient’s public key:
Decryption
-
Use the private key to compute the original message:
-
Convert back to the original message
Explain why RSA Encryption/Decryption makes sense i.e. decryption of the cipher text return the same number back.