"Public key" and "private key" show up everywhere — TLS (HTTPS), digital signatures, passkeys. No attack steps here — just the idea of public-key cryptography and the practical defenses worth knowing.
The roles of the public and private key
The keys come as a pair, with opposite roles — that's the whole point.
Public key vs private key vs symmetric key
The three kinds of key people mix up, side by side. The public and private key always come as a pair; a symmetric (shared) key belongs to a different kind of scheme.
| Public key | Private key | Symmetric key | |
|---|---|---|---|
| Who holds it | Anyone (safe to share) | Only the owner | Both parties hold the same key |
| Main job | Encrypt, verify signatures | Decrypt, create signatures | Both encrypt and decrypt |
| If it leaks | No problem (it's public anyway) | Impersonation or decryption becomes possible | That traffic can be read |
| Common schemes | RSA, elliptic curves (ECDSA, Ed25519, ECDH) | Same | AES, ChaCha20 |
| Speed | Slow | Slow | Fast |
Public-key operations are expensive, so they aren't used to encrypt bulk data. Real protocols use public-key crypto only to exchange keys and prove identity, and protect the data itself with symmetric encryption.
Why the public key doesn't reveal the private key
The two keys correspond mathematically, but working backwards from the public key to the private key isn't feasible in any realistic time. RSA relies on how hard it is to factor very large numbers; elliptic-curve cryptography relies on the elliptic-curve discrete logarithm problem.
That only holds with long enough keys. NIST's transition guidance (SP 800-131A) requires RSA keys of at least 2048 bits. For new keys, RSA 3072 bits or more, or an elliptic-curve scheme such as Ed25519, is the usual choice.
What it's used for
Encryption (private exchange)
- encrypt with the recipient's public key
- only the holder of the matching private key can decrypt
- in TLS, used to safely share a symmetric key
Digital signatures (proving authenticity)
- the sender signs with their private key
- the receiver verifies with the public key — identity + integrity
- used for TLS certificates, software distribution, passkey auth
Real TLS (HTTPS) is hybrid: public-key crypto safely shares a symmetric key, then the fast symmetric cipher protects the rest. Passkeys sign with a private key held on your device and verify with the server's public key — phishing-resistant authentication.
Examples: everyday uses, and incidents where a private key leaked
- HTTPS
- The server certificate carries the public key; the server proves it is genuine with its private key
- SSH login
- You register a public key on the server and log in by signing with your local private key — no password is sent
- Software distribution
- The publisher signs with a private key; users check with the public key that nothing was altered
- Passkeys
- The device signs with its private key; the service verifies with the registered public key
Most incidents come from how the private key was handled, not from the mathematics. In 2014, Heartbleed (CVE-2014-0160) let a bug in TLS software read out server memory, which could include the server's private key. Fixing the bug was not enough: keys had to be regenerated and certificates reissued. In the 2018 Coincheck NEM theft, a private key kept in an internet-connected environment was stolen, and that single key moved crypto assets worth about ¥58 billion.
How to check your own setup
Look at your site's certificate and key type
Open the certificate from the padlock (site information) icon in the address bar to see the issuer, expiry and public-key type (RSA 2048-bit, ECDSA P-256 and so on). On the command line, the output of openssl s_client -connect example.com:443 shows the same.
Check your SSH key type and length
Run ssh-keygen -l -f ~/.ssh/id_ed25519.pub against a public-key file to print its length and type. Regenerate anything old like RSA 1024-bit, and check the server's authorized_keys for public keys nobody uses any more (→ least privilege for SSH keys).
Make sure no private key sits in your code
Look for PEM private-key header lines (lines containing "BEGIN" and "PRIVATE KEY") in repositories and config files. To check a snippet by pasting it, use the Secret Leak Scanner; to block it automatically before each commit, use gitleaks as a pre-commit hook.
What's changing: preparing for quantum computers
A sufficiently capable quantum computer is expected to break RSA and elliptic-curve cryptography. In August 2024 NIST published the first post-quantum standards (FIPS 203 for ML-KEM, FIPS 204 for ML-DSA, FIPS 205 for SLH-DSA). It has also proposed, in a draft (NIST IR 8547), deprecating the classical schemes after 2030 and disallowing them after 2035.
Individuals and small sites don't need to implement post-quantum crypto themselves. If you keep the OS, browsers and TLS libraries updated, support arrives on its own. The realistic preparation is not to pin old libraries or old settings in place.
What to get right
Don't roll your own crypto
Even correct theory gets broken by implementation details — randomness quality, padding, timing. Use standard protocols and proven libraries; avoid custom implementations.
Protect the private key
Keep private keys out of code and repos. Isolate them in a keystore / secret manager, and run things so you can revoke and reissue (rotate) on leak (→ keep secrets out of public directories).
Keep key length and algorithms current
Recommendations change over time. Don't leave old key lengths or deprecated algorithms in place. Auto-renew certificates with Let's Encrypt and friends.
This site's view: the user's job is key management
Public-key crypto itself is strong; there's rarely a need to break it. Real-world incidents aren't about the math but about where the private key lives, whether you can revoke it, and stale settings left in place. This site isolates private keys off the public surface and rotates on any suspicion of leak, treating it as "assume it was read." Don't roll your own; use the standards. That's the safest approach.
Sources (primary)
- NIST SP 800-131A Rev. 2, "Transitioning the Use of Cryptographic Algorithms and Key Lengths" — csrc.nist.gov (minimum key lengths)
- NIST, "NIST Releases First 3 Finalized Post-Quantum Encryption Standards" (August 13, 2024) — nist.gov (FIPS 203, 204, 205)
- NIST IR 8547 (initial public draft), "Transition to Post-Quantum Cryptography Standards" — csrc.nist.gov (proposed deprecation after 2030, disallowance after 2035)
- IETF RFC 8446, "The Transport Layer Security (TLS) Protocol Version 1.3" — datatracker.ietf.org (key exchange and signature-based authentication)