seegongsik
Saved words
Security

The magic of two keys, public key

Last lesson we saw locking and unlocking with one same key. It was fast and clean, but one headache remained: how do you secretly hand that key to someone far away? But what if the key that locks and the key that unlocks were different? What if you could give the locking key to the whole world, while keeping the unlocking key only to yourself?

01

There are two keys

The symmetric key last lesson was a single key.
You locked with that one and unlocked with that one.
Public key cryptography is different here.
It uses a pair of two keys.
One is the public key.
As the name says, fine to give to anyone.
The other is the private key.
This one you keep only to yourself and never hand out.
The two keys are made together as one pair,
like siblings that match each other.

Tap a key to inspect its role

Tap each key to inspect it. The public key is shared with anyone, the private key is kept only by you.

The public key was fine left wide open.
The private key had to stay deeply hidden.
Same pair, but opposite roles.
One is announced to the world,
one is kept secret to the very end.
A natural question arises here.
If there are two keys,
which do you use to lock,
and which to unlock?
Next we look at the locking side first.

02

Lock with the public key

Say you want to send someone a secret message.
First you get that person's public key.
A public key is open to anyone, so it is easy to obtain.
You lock the message with that public key.
Locking with a public key
is like snapping a received padlock onto the message.
Anyone can snap the padlock shut.
But once it is shut,
even the person who locked it cannot open it.
A public key only locks, it does not unlock.

HELLOmessage
public key
Anyone can lock with the public key they hold.

Tap the public key to lock the message. A padlock snaps shut with the public key anyone holds.

Tapping the public key, the message got locked.
Now the message is in an unreadable shape.
The key point is this.
What locked it was the public key, not a secret.
So locking really can be done by anyone.
Yet once it is locked,
even the one who locked it cannot reopen it.
The key that opens a padlock locked by a public key is a separate one.
What could that key be?
Next we open it.

03

Only the private key opens it

A padlock locked by a public key
opens only with its matching private key.
Present the private key of the same pair and it clicks open,
present a wrong other key and it will not budge.
Even the public key that locked it cannot open it.
The key that locks and the key that opens
are entirely different.
So only the one person holding the private key
can read that message.
Even if the whole world holds the public key,
the right to read belongs only to the private key's owner.

Present a key to open the padlock

Try each key in turn. Only the matching private key opens the padlock, every other key fails.

It opened only when the matching private key was presented.
The public key and the wrong key both failed.
This asymmetry is the heart of public key cryptography.
Locking by anyone, unlocking by one person only.
The power to lock is left wide open,
and only the power to unlock is firmly locked away.
Thanks to this very property,
the headache from last lesson is solved.
The need to deliver a key in secret
disappears entirely.
Next we see that solution.

04

The key distribution problem is solved

With symmetric keys, one same key
had to be held identically by both sides.
So handing that key over secretly was the headache.
If someone intercepts it on the way, it is over.
The public key has no such worry.
A recipient's public key is safe to publish.
If someone takes it, all they can do is lock.
The private key that opens never leaves the owner's hand from the start.
So there is no key to deliver in secret at all.
The dangerous delivery step itself is gone.

Tap a way to compare its steps
Tap a way to compare its steps

Tap to compare the two ways. Symmetric needs a secret delivery, but the public key is safe to publish, so that step is gone.

Placing the two ways side by side,
the difference was clear.
The symmetric row always wedged in
the risky step of secret delivery.
The public key row has that step gone entirely.
You just leave the public key published.
Fast symmetric keys and safe key sharing
are in practice often used together,
but that story we leave for a later lesson.
For now, just clearly carry away
how the public key solved the key distribution problem.

05

Let's wrap up

Gathered on one line, it is this.
Public key cryptography uses a pair of two keys.
The public key is given to anyone,
the private key is held only by you.
What the public key locks opens only with the matching private key.
Locking by anyone, unlocking by one person only.
So the public key is safe to publish,
and there is no key to deliver in secret at all.
This is how the symmetric key's distribution problem is solved.
The public key hands out padlocks, the private key is your own key.

1two keys
2lock with public key
3opens only with private key
4key distribution solved

Tap the key points in order to review. (two keys -> lock with the public key -> opens only with the private key -> key distribution solved)

Now you know the magic of two keys.
With a key you give out and a key only yours,
it is a way to exchange secrets safely.
This one pair of keys is not only for locking and unlocking.
Flip the order and lock first with the private key,
and this time you can do something else.
It becomes a mark that the message is truly from you,
a signature that cannot be forged.
Next, with the same one pair of keys,
let's look at the digital signature together.

In one linePublic key cryptography uses a pair of two keys. One is the public key, fine to give to anyone, and one is the private key, held only by you. What the public key locks opens only with its matching private key. No other key, not even the public key that locked it, can open it. So a recipient's public key is safe to publish to the whole world. Anyone can lock a message with that public key, and only the person holding the matching private key can open it. The key distribution headache of symmetric keys disappears, because there is no secret key to hand over at all. The public key is like handing out padlocks, the private key is your own key. That is the magic of two keys.
Security
Was this helpful? Support seegongsik