Tech

Public-Key Cryptography

It's like handing out open padlocks to anyone who wants one, while the only key that opens them stays in your pocket.

  • 4 min read
  • 1 figures
  • Verified 2026-10-13

Definition

Public-key cryptography is an encryption method that uses two different keys: one to lock and one to unlock. The locking key is shared with everyone, and only the owner keeps the unlocking key. That lets you talk securely with someone you've never met, without sharing a secret key ahead of time.

How do you hand over the key to lock a note?

Say you want to pass a note to a friend so that no one else can read it. You could put the note in a box, lock it, and hand it over. The catch is that your friend has to be able to open that box too.

So you'd have to give your friend a copy of the key first. But what if the path you use to hand over that key isn't safe? If someone copies the key along the way, every note after that can be read.

It gets worse as more people join. If you want to swap secret notes with twenty classmates, you'd need to make and keep track of twenty different keys. Handing out keys turns out to be the weakest link.

The internet has the same problem. You've never met a shopping site you're visiting for the first time, so you've never traded keys with it. The idea that solves this is to split the locking key from the unlocking key.

Just scatter open padlocks everywhere

This time, imagine making a padlock and key as a matched pair, then copying only the padlock and handing it out. Anyone can grab one and snap it shut. But the key that opens a snapped padlock stays only in your pocket.

If someone wants to send you a secret note, they lock the box with the padlock you've handed out and send it over. If a stranger grabs the box along the way, they can't open it. Even the person who locked it can't open it again.

The padlock you spread around is called the public key. The key only you hold is called the private key. The two are born as a pair, but they're built so that looking at the padlock won't help anyone figure out the key in any realistic amount of time.

That's why it's fine to send your padlock to anyone. A website hands its padlock to every visitor first thing. One catch: someone in the middle could swap in their own padlock, so there needs to be a separate way to check that the padlock is the real one. Either way, you no longer have to meet in person to share a key beforehand.

A little more precisely

The matched pair of keys can do another job too. With your own key (the private key), you can put a stamp on a note that only you can make. Anyone with your padlock (the public key) can check that the stamp is really yours. The note's contents aren't hidden, but the stamp is useful in a different way.

A valid stamp means it was made with your key and the contents haven't changed since. This tool for proving who sent something is called a digital signature. Your private key works as your personal stamp.

There's a downside, though: this method is slow. Putting a big file straight into this kind of padlock takes a long time. So on today's internet, the two sides first use the padlock to confirm the other party is the real thing. Then they swap some values and each computes the same short secret key. The rest of the conversation runs quickly on that one key.

So when you pay at an online store today, both of these are working together. Your browser first checks the site's padlock using a stamp (a certificate) that a trusted certificate authority put on it, to make sure the padlock wasn't swapped out. Then it locks the rest of the conversation with the secret key they agreed on. Locking a message with the padlock is one of the main ways public keys get used.

Common misconceptions

Myth

If you tell people your public key, your encryption can be broken.

Fact

A public key is a padlock for locking, so it's fine to share widely. Even if someone takes the padlock apart and studies it, today's computers can't work out the unlocking key in any realistic amount of time. That's how it's designed.

Myth

A box locked with a public key can be opened again with that same public key.

Fact

Even the person who locked it can't open it with their own hands. Only the owner who holds the matching private key can open it.

Where you meet it

  1. When you visit a site that shows a padlock icon in the address bar, your browser uses the site's public key and certificate to check that it's really that site.

  2. In a messaging app's secret chats, this method is also used to set up a secret key that only you and the other person know. The actual messages are then locked with that key.

In one sentence

You give the locking key to everyone and keep the unlocking key to yourself, so you can exchange secrets safely without ever having to meet first.

Created 2025-12-22 Updated 2026-10-13 Verified 2026-10-13