Public key cryptography
Asymmetric cryptography gives everyone a matched pair of keys: a public key you can publish freely, and a private key that never leaves you.
In this lesson
- Explain what public and private keys are for
- Contrast key sizes of RSA and elliptic-curve algorithms
- Generate and inspect a key pair
The trapdoor
A public/private key pair is mathematically linked: what the public key does, only the private key can undo — and vice versa. Anyone can encrypt to your public key; only you can decrypt. Anyone can verify your signature; only you could have produced it.
The security rests on a trapdoor function: easy in one direction, infeasible without the secret (integer factorisation for RSA, the discrete logarithm on elliptic curves for ECC).
| Algorithm | Equivalent security | Typical key size | Common use |
|---|---|---|---|
| RSA-2048 | 112-bit | 2048 bits | Legacy TLS, S/MIME |
| RSA-4096 | 140-bit | 4096 bits | Root certificates |
| ECDSA P-256 | 128-bit | 256 bits | Bitcoin, Web PKI |
| Ed25519 | 128-bit | 256 bits | SSH, modern protocols |
| X25519 | 128-bit | 256 bits | TLS 1.3 key exchange |
Key derivation
Deriving a public key is fast and safe to publish; reversing it is the discrete logarithm problem.
Example · SSH keys
You generate id_ed25519 locally, upload the .pub file to the server, and log in without a password. The server only ever sees your public key; authentication proves you hold the private half.
ssh-keygen -t ed25519 -C "you@example.com"\n# public: ssh-ed25519 AAAAC3Nz... you@example.com\n# private: OPENSSH PRIVATE KEY (keep it secret)
Key pair playground
Generate a pair, encrypt with the public key and try to decrypt without the private one.
Your private key is your identity
Anyone holding it can impersonate you. Store it on hardware or an encrypted disk, never commit it to git, and rotate it if a machine is compromised.
Why not use asymmetric encryption for everything?
It is 100-1000x slower. Real protocols use it once (to agree on a session key), then switch to fast symmetric encryption.
What is a certificate?
A certificate is your public key signed by a Certificate Authority, binding it to a domain name. It is how browsers know the key they received really belongs to the site.