Information SecurityUnit 510 min read
Public Key Cryptography: Algorithms, RSA, Diffie-Hellman, Digital Signatures
Unit 5 of Information Security explores public key cryptography, covering asymmetric encryption, RSA algorithm, Diffie-Hellman key exchange, digital signatures, and their real-world applications in secure communications, e-commerce, and authentication systems.
Core Concepts
What is Public Key Cryptography?
Public key cryptography (also called asymmetric cryptography) uses two mathematically linked keys:
- Public Key: Shared openly (e.g., on a website or server).
- Private Key: Kept secret by the owner.
Unlike symmetric cryptography (e.g., AES), different keys are used for encryption and decryption. This solves the key distribution problem—no need to securely share a single key beforehand.
Why is this revolutionary?
- No pre-shared secret: Alice can encrypt a message with Bob’s public key, and only Bob (with his private key) can decrypt it.
- Digital signatures: Bob can sign a message with his private key, and anyone can verify it with his public key.
Key Algorithms
1. RSA (Rivest-Shamir-Adleman)
How it works: RSA relies on the difficulty of factoring large primes. The steps are:
- Key Generation:
- Choose two large primes and .
- Compute (the modulus).
- Compute Euler’s totient .
- Choose a public exponent (e.g., 65537) such that and .
- Compute the private exponent as the modular inverse of modulo : .
Encryption: For a message , the ciphertext is:
Decryption: The original message is recovered as:
Worked Example: Encrypting "HELLO" (ASCII values) with RSA Assume:
- , , so .
- , , .
Convert "HELLO" to ASCII: [72, 69, 76, 76, 79].
Encrypt the first letter (72):
Decrypt:
Real-World Tie-In: eSewa Transactions When you pay via eSewa, your public key is used to encrypt your transaction details (e.g., amount, recipient). Only eSewa’s server (holding the private key) can decrypt and process it. This ensures end-to-end encryption even if the network is compromised.
2. Diffie-Hellman Key Exchange
Problem: How to securely share a symmetric key over an insecure channel? Solution: Use exponential modular arithmetic to derive a shared secret.
Steps:
- Agree on a prime and a generator (public parameters).
- Alice picks a private key , computes , and sends to Bob.
- Bob picks a private key , computes , and sends to Alice.
- Both compute the shared secret:
Why it’s secure:
- An eavesdropper sees but cannot compute without knowing or (assuming the Discrete Logarithm Problem is hard).
Worked Example: Shared Secret Calculation Let , .
- Alice picks , computes .
- Bob picks , computes .
- Shared secret: (Both compute , the actual shared key.)
Real-World Tie-In: WhatsApp Calls WhatsApp uses Signal Protocol, which combines Diffie-Hellman with RSA to establish a secure session key for voice/video calls. Even if someone intercepts your messages, they can’t decrypt the call without the ephemeral keys exchanged during the handshake.
3. Digital Signatures
Purpose: Prove authenticity and integrity of a message. How it works:
- The sender signs the message with their private key.
- The receiver verifies the signature with the sender’s public key.
Steps for RSA Signatures:
- Hash the message to get a fixed-size digest .
- Sign the digest: (using the sender’s private key).
- Send to the receiver.
- The receiver computes and checks if .
Why it’s better than symmetric signatures:
- No need to securely share a secret key for verification.
- Tampering is detectable (hash mismatch).
Worked Example: Signing a Message Assume Bob’s RSA keys: , , . Message: "PAY 1000 NRS". Hash (simplified): . Signature: Verification:
Real-World Tie-In: NEPSE Stock Trades When you buy/sell shares on NEPSE, your trade order is digitally signed with your broker’s private key. The exchange verifies the signature using the broker’s public key to ensure the order is authentic and unaltered.
Comparison: Public vs. Symmetric Key Cryptography
| Feature | Public Key (Asymmetric) | Symmetric Key |
|---|---|---|
| Key Sharing | No pre-shared secret needed | Requires secure key exchange |
| Speed | Slower (computationally heavy) | Faster |
| Use Case | Key exchange, digital signatures | Bulk data encryption |
| Example Algorithms | RSA, ECC, Diffie-Hellman | AES, DES, Blowfish |
| Key Size | Larger (e.g., 2048-bit RSA) | Smaller (e.g., 128-bit AES) |
Advantages and Disadvantages
Advantages of Public Key Cryptography
- Secure Key Exchange: Solves the problem of distributing symmetric keys (e.g., Diffie-Hellman).
- Non-Repudiation: Digital signatures prove the sender’s identity (e.g., e-contracts).
- Scalability: Public keys can be freely distributed (e.g., HTTPS certificates).
- Forward Secrecy: Ephemeral keys (e.g., in TLS) limit damage if a private key is compromised.
Disadvantages
- Computational Overhead: Slower than symmetric encryption (e.g., RSA is 1000x slower than AES).
- Key Management: Private keys must be protected (e.g., lost keys = lost access).
- Implementation Complexity: Requires careful handling of large primes and modular arithmetic.
Real-World Applications
1. HTTPS (Secure Web Browsing)
- How it uses PKI: When you visit
https://esewa.com.np, your browser:- Verifies eSewa’s SSL/TLS certificate (signed by a trusted CA like Let’s Encrypt).
- Uses RSA or ECDHE (Elliptic Curve Diffie-Hellman) to establish a symmetric session key.
- Switches to AES-256 for fast encryption of your login details.
- Why it matters: Prevents man-in-the-middle attacks (e.g., fake login pages).
2. Khalti Payments
- Digital Signatures: When you authorize a payment, Khalti signs the transaction with its private key. The bank verifies this signature to confirm the payment is legitimate.
- Key Exchange: Khalti’s app uses ECDH to securely negotiate a session key with the bank’s server before encrypting your card details.
3. Ncell’s Secure SMS
- Public Key Encryption: Ncell uses asymmetric encryption to send OTPs. Your phone’s public key (embedded in the SIM) encrypts the OTP, and only your phone (with the private key) can decrypt it.
- Prevents SIM Swapping: Even if an attacker steals your SIM, they can’t decrypt the OTP without the private key.
Security Considerations
Threats to Public Key Cryptography
- Brute Force Attacks: Factoring in RSA or solving the discrete logarithm in Diffie-Hellman.
- Mitigation: Use large key sizes (e.g., RSA-4096, ECC-256).
- Quantum Computing: Shor’s algorithm can break RSA and ECC.
- Mitigation: Research post-quantum cryptography (e.g., lattice-based schemes).
- Private Key Theft: If a private key is leaked (e.g., via malware), all past communications can be decrypted.
- Mitigation: Use hardware security modules (HSMs) or key escrow.
Best Practices
- Key Storage: Use password-protected key containers (e.g., GPG, Bitwarden).
- Key Rotation: Regularly update private keys (e.g., every 1–2 years).
- Certificate Authorities (CAs): Always verify certificates (e.g., check the padlock icon in browsers).
Exam Tip
Public key cryptography is heavily tested in TU exams, especially:
- RSA Workings: Expect questions on key generation, encryption/decryption formulas, and modular arithmetic.
- Example: "Given , , , compute and encrypt ."
- Diffie-Hellman: Focus on shared secret calculation and security assumptions.
- Example: "Alice and Bob agree on , . Alice sends . If Bob’s private key is 15, what is the shared secret?"
- Digital Signatures: Understand hashing + signing and verification steps.
- Example: "Explain how RSA signatures prevent replay attacks."
- Real-World Scenarios: Relate concepts to e-commerce (eSewa, Daraz), banking (NMB, Global IME), or government systems (e-Dak).
- Example: "How does NTC use public key cryptography to secure online bill payments?"
Common Pitfalls:
- Forgetting to reduce modulo in RSA operations.
- Confusing public/private keys in encryption vs. signatures.
- Ignoring key size requirements (e.g., using RSA-1024 in 2024 is insecure).
A diagram showing hashing → signing → transmission → verification. (Image: FlippyFlink, CC BY-SA 4.0, via Wikimedia Commons)
Based on the TU BITM syllabus for Information Security (IT244), unit 5.
Discussion
Loading…