How public-key encryption works

· 2 min read

#how-it-works#security

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.

How public-key encryption moves a message Three boxes in a row: Sender, Ciphertext and Receiver. A dashed arrow 1 goes from the Receiver back to the Sender: the receiver publishes the public key. Arrow 2 goes from the Sender to the Ciphertext: the message is locked with the public key. Arrow 3 goes from the Ciphertext to the Receiver: it is unlocked with the private key, which only the receiver keeps. Sender uses the public key Ciphertext scrambled message Receiver keeps the private key 2 lock: public key 3 unlock: private key 1 the receiver publishes the public key
Simplified: real RSA also adds padding before it encrypts.

Step by step

  1. The receiver makes a key pair and publishes the public key.
  2. The sender encrypts the message with that public key.
  3. The ciphertext travels to the receiver.
  4. 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