Secret codes, keys and proof of who sent a message

10 min 6 sections 5 practice questions 11 sources cited

People have always scrambled messages so that only the right reader can understand them, and sealed or signed them so that the reader can trust where they came from. Computers do both with arithmetic. No background and no mathematics are assumed. A security professional meets these ideas wherever records are stored, information is sent or someone has to prove what was agreed.

By the end of this unit you will be able to:

  • Explain what encryption does, using the words plaintext, ciphertext and key
  • Tell apart one shared key from a pair of keys, and say what each is used for
  • Explain what a hash is and why it cannot be turned back into the original
  • State the three things a digital signature proves
  • Explain what a certificate is and who vouches for it

Examination results by email, and three worries

An illustrative example

A school office emails each pupil's examination results to the pupil's parents. One parent rings to say that the email came from an odd-looking address, and that the grade in it differs from the one on the printed slip.

The school secretary now has three worries. Did anyone else read the results on the way? Was the grade changed after it left the office? Did the email come from the school at all?

Which of the three worries would a locked box answer, and which need something more like a seal or a signature?

Encryption turns a readable message into a scrambled one

The Caesar cipher

Move every letter three places along the alphabet. MEET AT NOON becomes PHHW DW QRRQ. A reader who knows the rule moves each letter three places back and has the message again.

The readable message is the plaintext. The scrambled result is the ciphertext. Turning into is encryption, and turning it back is decryption.

A method that works on letters or bits, as this one does, is a cipher. A code swaps whole words or phrases for others, such as a codebook that writes 'eagle' for 'the director'.

Two things are at work in the Caesar . One is the method: move the letters along. The other is the key, the piece of information that makes one use of the method different from another. Here the key is the number 3.

In modern the method is published for anyone to examine, and all the secrecy lies in the key. A door lock is the same. How the lock works is no secret, and the security is in the shape of the key. This rule is called Kerckhoffs's principle.

A real key is a long number. Its length is given in bits, and each added bit doubles the number of keys an attacker would have to try.

Encryption keeps information private. On its own it does not show who wrote a message, or whether the message was altered on the way.

One shared key, or a pair of keys

The Caesar cipher uses one key for both directions. This is symmetric encryption: the same key scrambles and unscrambles, so sender and receiver must both hold it and keep it secret. It works like a house key with copies.

is fast. Its difficulty is the first step. The key has to reach the other person without being copied on the way, and a stranger on the other side of the world cannot be handed a key.

Asymmetric encryption answers that difficulty with two keys made together as a pair. The public key can be given to anyone. The private key never leaves its owner. When a pair is used to encrypt, a message locked with one key of the pair can be opened only with the other. Knowing the public key does not reveal the private one.

A letterbox in a front door

Anyone who knows the address can push a letter through the slot. Only the person with the door key can take the letters out. The slot is the public key, and the door key is the private key.

One shared key and a pair of keys compared
PointOne shared key (symmetric)A pair of keys (asymmetric)
KeysOne, used in both directionsTwo: one public, one private
Who holds themSender and receiver both hold the secretThe owner alone holds the private key. Anyone may hold the public key
SpeedFastMuch slower
Main difficultyGetting the key to the other side safelyBeing sure whose public key it is
Used forEncrypting large amounts of dataPassing a shared key safely, and

The two are used together. A pair of keys carries a freshly made shared key safely to the other side, and the shared key then encrypts the conversation.

A hash is a fingerprint of a file

A hash function takes any amount of data, from one word to a whole film, and works out a short value of fixed length called a hash. Other names for the value are a digest and a .

A well-designed has five properties.

  • The same data always gives the same hash.
  • Changing the data at all, even by one comma, gives a different hash.
  • The hash cannot be worked backwards into the data. It is a one-way process.
  • Finding two different pieces of data with the same hash is not practical.
  • A plain hash uses no key. Some checks add a to the hash, and are a different tool.

Two older hash functions, MD5 and SHA-1, have lost the fourth property: practical attacks can find two pieces of data with the same hash, so neither is trusted for this purpose.

A fingerprint is the nearest everyday thing. It is small, it identifies one person, and nobody can rebuild the person from it.

A hash shows whether data has changed. The hash is worked out once and kept. Later it is worked out again, and if the two values differ, the data is not what it was.

Common misconception

“Hashing is a kind of encryption.”

Encryption is made to be undone by whoever holds the key. A plain hash has no key and cannot be undone by anyone. Encryption keeps data private, and a hash shows whether data has changed.

A hash has one gap. Anyone who alters the data can work out a new hash to match, so a hash proves nothing about who produced it.

A digital signature proves who signed and that nothing changed

A digital signature closes that gap by bringing in the signer's private key.

  1. The signer's software works out the hash of the document.
  2. It combines the hash with the signer's private key. The result is the signature, which travels with the document.
  3. The reader's software tests the signature against the document, using the signer's public key.
  4. A document changed by one character, or a signature made with any other private key, fails the test.

A signature that passes proves three things.

  • Who signed: the holder of the private key, and nobody else.
  • That nothing has changed since signing.
  • That the signer cannot credibly deny having signed. This third proof is called non-repudiation.

A wax seal pressed with a ring that only one person owns made the same three claims for a letter.

A signature hides nothing: the document stays readable. Hiding and signing are separate jobs, and they use the keys in opposite directions.

To hide a message: the receiver's public key. To sign a message: the sender's own private key.

A digital signature is not a typed name or a scanned handwritten signature. Those are text and pictures, which anyone can copy.

How a reader checks a digital signature

How a reader checks a digital signatureThe signer hashes a document and combines the hash with the private key to make a signature. The reader's check tests the signature against the document with the public key from a certificate, and the check passes or fails.Documentreadable by allHasha fingerprintPrivate keythe signer's,never sentSignaturetravels with itCertificatePublic keyReader'scheckPasseswho signed,nothing changed,cannot be deniedFailschanged, oranother key:do not trust itsent togetherHow a reader checks a digital signatureThe signer hashes a document and combines the hash with the private key to make a signature. The reader's check tests the signature against the document with the public key from a certificate, and the check passes or fails.Documentreadable by allHasha fingerprintPrivate keythe signer's,never sentSignaturetravels with itCertificatePublic keyReader'scheckPasseswho signed,nothing changed,cannot be deniedFailschanged, oranother key:do not trust itsent together
Read this figure as text

A digital signature proves who signed and that nothing changed, and it hides nothing. The figure follows a document from the signer to the reader's check and the two outcomes the check can have.

  1. The signer's software works out the hash of the document: a short fingerprint of fixed length.
  2. It combines the hash with the signer's private key, which the signer alone holds and never sends. The result is the signature.
  3. The private key stays at the signer's end. Nothing on the reader's side ever holds it.
  4. The document travels with the signature to the reader, and it stays readable throughout.
  5. The reader's software tests the signature against the document it received.
  6. It uses the signer's public key, taken from a certificate. The certificate states that the public key belongs to the signer and is itself signed by a certificate authority.
  7. If the test passes, the document came from the holder of the private key, has not changed since signing, and the signer cannot credibly deny signing it.
  8. If the test fails, the document was changed or the signature was made with a different private key, and it is not to be trusted.

A certificate says whose public key this is

One difficulty remains. A public key is only a number. A reader needs a reason to believe that it belongs to the bank, and not to an impostor using the bank's name.

A certificate supplies the reason. It is an electronic document that states which person or organisation a public key belongs to. It carries a start date and an end date, and it is digitally signed by a trusted organisation called a certificate authority (CA), also written . The certificate authority is responsible for checking who the owner is before it signs.

A passport is built in the same way. It ties a face to a name, it is issued by an office that checked, it expires, and it is believed because the issuer is trusted.

A can be cancelled before its end date, for instance when the private key has been stolen. Cancelling it is called revocation.

A website's name, as typed in a browser, is its web address. One beginning https asks for a protected connection. The server then presents its certificate. The browser checks the name, the dates and the certificate authority's signature before anything private is sent. Phones and computers come with a list of certificate authorities they already trust.

A certificate is public. It contains the public key and never the private one.

Four tools for four different worries

Which tool answers which worry
WorryToolWhat it relies on
Someone else may read itEncryptionA key kept secret
It may have been changedHashA trusted copy of the earlier hash
It may not be from the sender named, or the sender may deny itDigital signatureThe signer's private key
The public key may not be the owner'sCertificateA trusted certificate authority

The school's three worries map onto the table. A locked box is encryption, and it answers only the first: nobody else read the results. The changed grade and the doubtful sender both call for a digital signature from the school. The parents' software would test that signature with the school's public key, and a certificate would show that the key is the school's.

Each tool does one job. Encrypting a message says nothing about who sent it, and signing a message hides nothing.

A question, worked through

A firm of solicitors emails contracts to its clients. One client says the contract she received shows a different price from the one she agreed. In another case a partner says that a contract a client is relying on was never sent by the firm. The firm wants future contracts to settle both kinds of dispute.

Which measure BEST meets that need?

  1. Encrypt each contract with a key shared with the client
  2. Digitally sign each contract with the firm's private key
  3. Send the hash of each contract in a separate email
  4. Encrypt each contract with the client's public key
Decide on your answer, then open the reasoning
  1. Two things are in dispute: whether a contract was changed, and whether it came from the firm. The BEST measure has to settle both.
  2. Rule out a and d. Encryption keeps a contract private on its way, and neither dispute is about privacy. With a shared key, either side could also have produced the contract.
  3. Option c is closer. A hash would show that a contract had changed. But anyone who can send an email can send a hash, so it does not show where the contract came from.
  4. Option b uses the firm's private key, which only the firm holds. A signature that passes shows that the contract is unchanged and came from the firm, and the firm cannot later deny sending it.
  5. The answer is b. If the contracts also had to be kept private, encryption would be added to the signature and would not replace it.

Answer: B. Digitally sign each contract with the firm's private key

Choosing between good answers

A question asks that only the intended reader can see a message or a file
look for encryption. A hash or a signature leaves the content readable.
A question asks for proof that data has not changed
a hash is enough if the earlier hash is kept safe. If the proof must also show who produced the data, choose a digital signature.
A question asks that a sender cannot later deny sending
choose a digital signature. A shared key cannot give this, because both sides hold it and either could have made the message.
A scenario turns on whether a public key or a website is genuine
look for the certificate and the certificate authority that signed it.

Try it

Follow a browser as it checks a server's certificate, then change one fact and find the check that fails.

Loading the preview.

Check your understanding

5 questions on this unit, easiest first. Confirm an answer to see the reasoning for it, then the right answer, the other options and the rule to reuse. Your answers are kept in this browser and feed readiness and review.

These questions are drafts that no named reviewer has approved yet.

Question 1 of 5

Match each word to its plain meaning.

Choose the match for each entry. Every match has to be right.

What to remember

  • Encryption turns plaintext into ciphertext with a key, and keeps information private. It does not show who sent a message.
  • Symmetric encryption uses one shared key and is fast. Asymmetric encryption uses a public key and a private key, and solves the problem of sharing a key with a stranger.
  • A hash is a short, fixed-length fingerprint of data. A plain hash uses no key, cannot be reversed and shows whether data has changed.
  • A digital signature is made with the signer's private key and checked with the public key. It proves who signed, that nothing changed and that the signer cannot deny it.
  • A certificate ties a public key to a named owner and is signed by a certificate authority.

Say it from memory

  1. What does Kerckhoffs's principle say about the method and the key?

    The method of encryption is published for anyone to examine, and all the secrecy lies in the key. A door lock works the same way: how the lock works is no secret, and the security is in the shape of the key.

    Read this part again

  2. How do symmetric and asymmetric encryption differ, and how are they used together?

    Symmetric encryption uses one shared key in both directions and is fast. Asymmetric encryption uses a pair: a public key anyone may hold and a private key only its owner holds, and it is much slower. A pair of keys carries a freshly made shared key safely across, and the shared key encrypts the conversation.

    Read this part again

  3. Name the five properties of a well-designed hash function.

    The same data always gives the same hash. Changing the data at all gives a different hash. The hash cannot be worked backwards into the data. Finding two different pieces of data with the same hash is not practical. A plain hash uses no key.

    Read this part again

  4. Which key hides a message and which key signs it, and what three things does a valid signature prove?

    To hide a message, use the receiver's public key. To sign it, use the sender's own private key. A signature that passes proves who signed, that nothing has changed since signing, and that the signer cannot credibly deny signing, which is non-repudiation.

    Read this part again

  5. What does a certificate state, who signs it, and what is revocation?

    A certificate states which person or organisation a public key belongs to, carries a start and an end date, and is digitally signed by a certificate authority that checked the owner. Revocation is cancelling a certificate before its end date, for instance when the private key has been stolen.

    Read this part again

Sources