Checking a letter is real, the signature
Last lesson we saw that what a public key locks opens only with the matching private key. But sometimes a message need not be secret, and you only want to confirm it truly came from that person. What if someone borrowed their name and sent a fake letter? What if the sender left a stamp-like mark with the private key only they have, and anyone could check that mark is genuine using that person's public key?
If you do not know who sent it
Say a letter arrives.
At the end is someone's name.
But did that person really write it?
Anyone can copy down a name.
The content too may have been quietly altered.
From the letters alone there is no way to tell.
It is not a question of secret or not.
The content can be fully out in the open.
You only want to know whether it truly came from that person,
and whether it was unchanged on the way.
Inspect a letter with only a name. From the text alone you cannot tell a copied name from a real one, or whether the content was changed.
Trying it yourself was frustrating.
Even with a name written, you cannot be sure.
The altered letter looked perfectly fine too.
We need two things.
One, proof it truly came from that person.
Two, proof it was unchanged on the way.
It would be nice to have one mark that shows both at once.
And it must be one that nobody else can imitate.
Luckily, the one pair of keys from last lesson
can do exactly that.
Sign with the private key
Last lesson you locked with the recipient's public key.
A signature goes the opposite direction.
The sender uses their own private key.
With the private key they attach a signature to the message.
This is not locking with a padlock.
It is more like stamping a seal beside the message.
The content stays fully visible.
Only, that seal travels along with it.
Since only that person holds the private key,
only that person can stamp this seal.
Tap the private key to attach a signature to the message. The content stays visible, and a seal only that person can make travels with it.
Tapping the private key, a signature got attached.
Not one letter of the message was hidden.
It was not locked, only a seal was added.
This signature is tied to the message content.
That very point matters next.
And to stamp this seal,
you must have that person's private key.
The private key never leaves its owner's hand,
so no one else can make the same seal.
Then how does the receiving side check this?
Verify with the public key
The receiver uses that person's public key.
A public key, recall, is open to anyone.
With that public key they verify the signature.
Verifying is asking a question.
Was this seal really stamped with that private key?
If yes, verification passes.
The public key and private key are one pair,
so it passes only when the pair matches.
A seal stamped with the wrong person's private key
fails when checked against that public key.
Verify several signatures with that person's public key. Only the one stamped by the matching private key passes, others fail.
Only the signature stamped by the matching private key passed.
The ones stamped with a wrong key all failed.
What passing means is clear.
This message truly came from that person.
The public key is fine for the whole world to hold.
With a public key you can only verify, not make a signature.
The power to stamp the seal belongs only to the private key's owner,
while checking the seal is open to anyone.
This is the mirror image of last lesson's locking.
Yet passing does not speak of authenticity alone.
Real, and unchanged
The signature is firmly tied to the message content.
So passing verification says two things at once.
One is authenticity, that it truly came from that person.
The other is integrity, that not one character changed.
If someone alters the content even slightly on the way,
it no longer fits the tied signature.
Then verification breaks at once.
A single changed character becomes the alarm.
So passing means both that it is real
and that it was untouched on the way.
Change one character of the signed message. The signature tied to the content no longer fits, and verification breaks.
Just one changed character,
and verification turned to failure at once.
The tied signature no longer matches.
The receiver sees this failure and realizes
this is not as it originally was.
So they can stop instead of trusting it carelessly.
This very breaking guards integrity.
There is no being fooled into taking an altered message as real.
Authenticity and integrity, one seal guards both at once.
Now let's lay locking and signing side by side.
Let's wrap up
Gathered on one line, it is this.
A digital signature uses public key cryptography in reverse.
The sender signs the message with their own private key.
The receiver verifies with that person's public key.
If it passes, it is proven together that it truly came from that person
and was unchanged on the way.
Locking keeps content secret,
signing proves who sent it and that it was not altered.
The same one pair of keys, just flipped in direction, does both.
Locking is for secrecy, signing is for authenticity and integrity.
Tap lock and sign to compare. Locking is for secrecy, signing is for authenticity and integrity, the difference in one line.
Now you know the difference between locking and signing.
Locking keeps a secret,
signing proves it is real and unchanged.
Both come from the same one pair of keys.
Lock with the recipient's public key for secrecy,
sign with the sender's private key for authenticity and integrity.
A single direction splits the use.
Yet for verification to hold, there is one premise.
That public key must really belong to that person.
How you trust that public key is the next story.