Unit 7: Online data security · Data encryption techniques

Article

Public key encryption

7 min read

You want to send your card number to an online shop you have never used. The shop cannot whisper a secret key to you first, because you have never met. With only one shared key, you are stuck. Public key encryption solves this by using two keys instead of one.

Two keys, one pair

In public key encryption, each person has a pair of keys that are made together:

  • The public key is not secret. The owner gives it to everyone. It is used to encrypt.
  • The private key is secret. Only the owner has it. It is used to decrypt.

The rule is: data locked with a public key can be unlocked only with the matching private key. The public key cannot unlock it.

Think of padlocks. Mia makes hundreds of open padlocks. They all fit one key, and she keeps that key. She hands out open padlocks to anyone. Ben puts a message in a box and snaps one of Mia's padlocks shut. Now even Ben cannot open the box. Only Mia's key can. The open padlock is the public key. Mia's own key is the private key.

Ben sends Mia a secret

  1. 1

    Ben → Mia

    Please send me your public key.

  2. 2

    Mia → Ben

    Here is my public key.

  3. Ben encrypts his secret with Mia's public key.
  4. 3

    Ben → Mia

    The ciphertext

  5. Only Mia's private key can decrypt it. She never sent it to anyone.
Someone watching the line sees Mia's public key and the ciphertext. Neither one lets them read the secret.

Check your understanding

Ben wants to send Mia a secret message using public key encryption. Which key does Ben use to encrypt it?

Why this fixes the key-sharing problem

With symmetric encryption, the secret key had to travel to your friend, and a spy could copy it. Here nothing secret ever travels. The public key can go over the Internet or sit on a website. The private key never leaves its owner.

A spy has the public key, so why can't the spy work out the private key? The two keys are linked by a maths problem that is quick to do one way and extremely slow to undo. A simple example: multiplying two huge prime numbers (numbers that only divide by 1 and themselves) is easy for a computer. Finding the two primes from the answer takes unreasonable time. This does not mean the system can never be broken. It means that with the methods we know today, working out the private key from the public key is practically impossible. This is why public keys are so long.

Symmetric or public key?

SymmetricPublic key
Keysone key, shared by botha pair: public and private
To encryptthe shared keythe receiver's public key
To decryptthe same shared keythe receiver's private key
What must stay secretthe shared keythe private key only
Key-sharing problemyesno
Speedfastslower

Because public key encryption is slower, the web uses both. Your browser first uses public key methods to set up a fresh secret key with a website. Then both sides switch to fast symmetric encryption for the rest of the conversation. The next article shows how your browser also checks that the public key really belongs to that website.

Check your understanding

What problem of symmetric encryption does public key encryption solve?

Worked example

Priya wants to send her card number to shop.example.

StepWhat happens
1The shop's public key is sent to Priya's browser.
2Her browser encrypts the card number with that public key.
3The ciphertext crosses the Internet. A spy copies it but cannot read it.
4The shop decrypts it with its private key.
5Only the shop can read the card number.

Priya never needed a secret from the shop, and the shop never needed one from Priya.

Common mistakes

  • Using the wrong key. You encrypt with the receiver's public key. The receiver decrypts with their own private key.
  • "The public key must be hidden." No. Sharing it is the whole point. Hide the private key.
  • "Anyone with the public key can read my messages." The public key only locks. It cannot unlock.
  • "Public key encryption can never be broken." It is practically impossible to work out the private key with known methods, but not proven unbreakable. A stolen private key breaks it at once.
  • "Both people need the same key." That is symmetric encryption.

On the exam

"Which of the following best describes public key encryption?" The answer: a public key, which anyone may know, encrypts, and a different, private key, which only the receiver has, decrypts. The exam also asks why it is useful: the sender and receiver never have to share a secret key first.

Key words

Public key encryption: encryption with a key pair. The public key encrypts, the private key decrypts.

Public key: the part of the pair that is shared with everyone.

Private key: the part of the pair that only its owner holds.

Key pair: a public key and the private key that matches it.

AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse, this site. All lessons and questions here are written by JrCodex.