How public-key encryption works
Public-key encryption uses a pair of keys: one you publish and one you keep secret. The idea to keep: anyone can lock a message for you, but only you can unlock it.
The short version
The two keys are linked: what one does, only the other can undo. You publish the public key, so anyone can encrypt a message to you. The private key stays with you and is the only thing that decrypts it. Signing runs the other way: the private key signs, and anyone can check the signature with the public key.
Step by step
- The receiver makes a key pair and publishes the public key.
- The sender encrypts the message with that public key.
- The ciphertext travels to the receiver.
- Only the receiver's private key decrypts it.
| Symmetric | Public-key | |
|---|---|---|
| Keys | one shared key | a pair, public and private |
| Speed | faster | much slower |
| Message size | can be long | limited by key size |
Why it matters
In practice the two are combined: a symmetric algorithm encrypts the message, and public-key encryption protects only the small symmetric key. The upside is that the public key can be handed out freely; the downside is speed and size. RFC 8017 asks new applications to use RSA-OAEP for encryption and RSA-PSS for signatures, and keeps the older PKCS1-v1_5 schemes for compatibility.
Sources
- Public-key cryptography — MDN Web Docs — key pair, encryption and signing directions, speed and message-size limits, hybrid use with a symmetric algorithm
- RFC 8017: PKCS #1 v2.2 — RSAES-OAEP and RSASSA-PSS for new applications, PKCS1-v1_5 for compatibility