Glossary

What is public-key cryptography: encrypting and signing with a key pair

Public-key cryptography uses a public and private key pair to encrypt and sign. How it underpins TLS, signatures and passkeys, and why to guard the private key.

Published 2026-07-04 Updated 2026-10-06 8 min read
On this page

"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
Safe to share. Encrypts / verifies signatures
private
Held only by the owner. Decrypts / makes signatures
if leaked
A leaked private key enables impersonation/decryption → revoke and reissue at once
The public key is safe to hand out. What the public key locks, only the matching private key opens. Signatures work in the opposite direction.

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 keyPrivate keySymmetric key
Who holds itAnyone (safe to share)Only the ownerBoth parties hold the same key
Main jobEncrypt, verify signaturesDecrypt, create signaturesBoth encrypt and decrypt
If it leaksNo problem (it's public anyway)Impersonation or decryption becomes possibleThat traffic can be read
Common schemesRSA, elliptic curves (ECDSA, Ed25519, ECDH)SameAES, ChaCha20
SpeedSlowSlowFast

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

Where public-key cryptography shows up
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

1

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.

2

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).

3

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

1

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.

2

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).

3

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)

FAQ

QHow is public-key crypto different from symmetric (shared-key) crypto?
A

Symmetric crypto uses the same key to encrypt and decrypt — fast, but you have to get that key to the other party safely. Public-key crypto uses a public + private pair, and the public key can be shared with anyone. In practice TLS (HTTPS) is hybrid: public-key crypto safely shares a symmetric key, then the bulk of the data is protected with the fast symmetric cipher.

QHow does a digital signature prove something is genuine?
A

The sender creates a signature over the data with their private key, and the receiver verifies it with the sender's public key. Because only the owner holds the private key, a passing check means 'the holder of that public key signed it, and the content wasn't tampered with.' TLS certificates and software-distribution authenticity rely on this signature mechanism.

QCan I implement my own crypto?
A

Avoid it. Even correct theory gets broken by implementation details — weak randomness, padding, timing differences. The rule is 'don't roll your own; use proven libraries and standard protocols.' Design how keys are generated, stored, and revoked (rotated), and keep key lengths and algorithms on the current recommendations.

QIf the public key is handed out, why can't anyone work out the private key from it?
A

The two keys are mathematically linked, but deriving the private key from the public key would require solving a problem that current computers cannot solve in any realistic time. RSA relies on the difficulty of factoring very large numbers; elliptic-curve schemes (ECDSA, Ed25519 and others) rely on the elliptic-curve discrete logarithm problem. That only holds with sufficiently long keys — old, short keys can be broken.

QMy private key may have leaked. What should I do?
A

Treat the key as read and stop it from being usable first. For a TLS certificate, ask the certificate authority to revoke it and reissue with a new key; for an SSH key, remove the public key from the server's authorized_keys and switch to a new pair; for a signing key, replace the published verification key and tell users. Renewing the certificate without generating a new key leaves the old private key usable.

QWill quantum computers break public-key cryptography?
A

A sufficiently capable quantum computer is expected to be able to break RSA and elliptic-curve cryptography. That is why the US National Institute of Standards and Technology (NIST) published post-quantum standards (FIPS 203, 204 and 205) in August 2024, and has 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 anything themselves; the realistic step is to keep the OS, browsers and libraries updated so the switch arrives on its own.