Explaining RSA Encryption

Soulaimaneyh
3 min readFeb 26, 2024

--

RSA is an asymmetric encryption algorithm that uses a public key for encryption and a private key for decryption. The security is based on the difficulty of factoring the product of two large prime numbers. This method is widely used for securing internet communications, online transactions, email encryption, and digital signatures.
Explaining RSA Encryption

RSA is an asymmetric encryption algorithm that uses a public key for encryption and a private key for decryption. The security is based on the difficulty of factoring the product of two large prime numbers. This method is widely used for securing internet communications, online transactions, email encryption, and digital signatures.

The algorithm involves exchanging a mathematically related pair of keys — a public key that can be freely shared for encryption and a private key kept secret for decryption.

Key Generation:

  • User A:
  • Generates a large prime number pair (p, q) and calculates their product (n = p * q).
  • Chooses a public exponent (e) that is relatively prime to a common factor (φ(n) = (p-1) * (q-1)).
  • Using modular arithmetic, calculates the private exponent (d) that satisfies the equation (e * d) ≡ 1 (mod φ(n)).
  • Public key: (n, e)
  • Private key: (n, d)

Key Exchange:

  • User A:
  • Makes their public key (n, e) widely available, for example, by publishing it on a website or sharing it with intended recipients.
  • Keeps the private key (n, d) secret and secure.

Encryption:

  • User B:
  • Wants to send a confidential message (M) to User A.
  • Obtains User A’s public key (n, e).
  • Converts the message (M) into a numerical format suitable for encryption (e.g., using a padding scheme).
  • Applies the public key encryption function:
  • Ciphertext ©: C = M^e (mod n)
  • The encrypted message © is now safe to transmit as it can only be decrypted by someone holding the corresponding private key.

Decryption:

  • User A:
  • Receives the encrypted message © from User B.
  • Uses their private key (n, d) to decrypt the message:
  • Decrypted message (M): M = C^d (mod n)

Only User A with the private key can decrypt the message because the mathematical relationship between the public and private keys makes it computationally infeasible to derive the private key from the public key information.

Authentication (Optional)

While hashing wasn’t covered, it’s commonly used with RSA for digital signatures.

First, User A initiates the communication by signing a message with their private key. This signature is then sent along with the encrypted message to User B. Upon receiving the encrypted message and its associated signature, User B undertakes a verification process. This verification utilizes User A’s public key to ensure two critical aspects: that the message indeed originated from User A and that it has remained unaltered during transmission.

First, User A initiates the communication by signing a message with their private key. This signature is then sent along with the encrypted message to User B. Upon receiving the encrypted message and its associated signature, User B undertakes a verification process. This verification utilizes User A’s public key to ensure two critical aspects: that the message indeed originated from User A and that it has remained unaltered during transmission.

This intricate three-step mechanism helps establish the authenticity of the communication and guards against potential tampering or unauthorized sources.

--

--