Apps & Data Security ยท 5.4

๐Ÿ”‘ Asymmetric Cryptography

Public keys, private keys, and knowing which key to use for which purposeโฑ ~2 min

๐Ÿ“ฌAsymmetric encryption is a special padlock system

Imagine everyone has a special padlock (public key) they give to anyone who wants to send them a secure message. Anyone can lock a box with your padlock, but only you have the key to open it (private key). To prove a message came from you, you use your private key to 'sign' it โ€” anyone with your public key can verify the signature, but only you could have created it. One key pair, two different uses: encrypt (use recipient's public key) or sign (use your own private key).

The Key Pair: Public and Private

  • โ€ขPublic key: share freely โ€” post it on your website, email it to anyone, publish it in a directory. There's no security risk in others having your public key.
  • โ€ขPrivate key: NEVER share โ€” stays on your device, ideally in a hardware security module (HSM) or secure enclave. If compromised, all trust in that key pair is destroyed; revoke and regenerate immediately.
  • โ€ขMathematical relationship: the two keys are generated together using math (RSA, ECC) such that what one encrypts, only the other can decrypt. But deriving the private key from the public key is computationally infeasible.
  • โ€ขAsymmetric encryption is slow: used for small data operations (key exchange, digital signatures) not bulk encryption. Typically used to establish a shared symmetric key, then switch to AES for data.

Six Use Cases โ€” Choosing the Right Key

GoalSecurity ObjectiveWhich Key?Who Uses ItWhy
Send Alice a secret message only she can readConfidentialityAlice's PUBLIC key to encryptSender (you)Only Alice's private key can decrypt โ€” she's the only one who can read it
Prove a message came from AliceAuthenticationAlice's PRIVATE key to signAliceOnly Alice has her private key; anyone with her public key can verify the signature
Verify a message wasn't modified in transitIntegrityAlice's PRIVATE key to sign hashAliceIf any bit changes, the hash changes; signature verification fails
Send message only Alice can read AND prove it came from youConfidentiality + AuthenticationAlice's public (encrypt) + YOUR private (sign)BothTwo separate operations: encrypt with recipient's public key; sign with sender's private key
Establish a shared secret without exchanging keysKey ExchangeDiffie-Hellman algorithmBoth partiesDH allows both sides to independently derive the same session key; used in TLS handshake
[TRAP] Encrypt with your OWN private key for 'secrecy'FAILS confidentialityWrong key choiceโ€”Anyone with your public key (which is public!) can decrypt it โ€” provides zero confidentiality. Don't do this.

Real-World Application: HTTPS / TLS Handshake

  1. 1.Browser requests server's public key certificate (signed by a trusted CA)
  2. 2.Browser verifies the certificate is legitimate (CA's digital signature validates)
  3. 3.Browser generates a random session key and encrypts it with the server's public key
  4. 4.Server decrypts with its private key โ€” now both have the same session key
  5. 5.All further communication encrypted with symmetric AES using the shared session key
  6. 6.Result: asymmetric crypto for key exchange, fast symmetric crypto for data โ€” best of both
โ˜… FactThe most common attack on asymmetric cryptography isn't breaking the math โ€” it's key management failures. The 2011 RSA SecurID breach: attackers stole seed values used to generate OTP tokens, compromising millions of hardware tokens. The DigiNotar CA breach (2011): attackers issued fraudulent certificates for Google.com, enabling man-in-the-middle attacks against Iranian users. Certificate revocation and CA trust are the real challenges in asymmetric cryptography at scale.
๐Ÿง Quick Checkfirst try = +5 XP

Alice wants to send Bob a message that (1) only Bob can read, and (2) proves the message came from Alice. Which combination of keys does Alice use, and in what order?

โญ 0 XP๐Ÿ”ฅ 0 days