OCR H446, section 1.3.1 (c)
Encryption scrambles data so that it can only be read by someone who has the right key. It protects data that is stored (on a disk) and data that is sent (across a network).
Terms
- Plaintext: the original, readable data.
- Ciphertext: the scrambled data after encryption.
- Cipher: the algorithm used to encrypt and decrypt.
- Key: a secret value that controls the cipher. Without it, the ciphertext can't be turned back into plaintext (in practice).
A good cipher is secure even if everyone knows how it works. The security depends only on keeping the key secret.
Symmetric encryption
In symmetric encryption, the same key is used to encrypt and decrypt.
A simple example is the Caesar cipher, where each letter is shifted along the alphabet by the key. Shifting HELLO by 3 gives KHOOR, and shifting back by 3 recovers it. Modern examples are AES and the older DES.
Advantages
- Fast, and needs little processing power, so it is good for large amounts of data, such as whole disks or streams.
- Strong when the key is long (for example 256 bits).
Disadvantages
- The key distribution problem. Both the sender and receiver need the same secret key, but how can it be sent safely? If someone intercepts the key, they can read everything.
- Needs a different key for each pair of people. For people to talk privately in pairs, you need keys. For 100 people that is 4950.
Asymmetric encryption
In asymmetric encryption (also called public key encryption), each user has a pair of mathematically linked keys:
- a public key, which is shared with anyone;
- a private key, which is kept secret by its owner.
What one key encrypts, only the other can decrypt.
Sending a secret message
- The receiver publishes their public key.
- The sender encrypts the message with the receiver's public key.
- Only the receiver's private key can decrypt it. Even the sender can't undo it.
Advantages
- No key distribution problem: the public key can be sent openly, and the private key never leaves its owner.
- Anyone can send a secret message to anyone, without meeting first.
- Can be used for digital signatures: a message signed with the sender's private key can be checked by anyone using the public key, proving who sent it and that it hasn't been changed.
Disadvantages
- Much slower than symmetric encryption, and needs more processing power.
- Keys are longer (for example 2048 bits), and it isn't practical for large amounts of data.
- It is only secure if the private key is kept safe, and you need to be sure that a public key really belongs to the person (which is what digital certificates are for).
Example: RSA.
Comparison
| Symmetric | Asymmetric | |
|---|---|---|
| Keys | One shared secret key | A public and private pair |
| Speed | Fast | Slow |
| Key distribution | A problem | Solved: the public key is shared openly |
| Number of keys for many users | Many (one for each pair) | One pair for each user |
| Best for | Bulk data | Exchanging keys, signatures, small messages |
| Examples | AES, DES | RSA |
Combining them: how HTTPS works
In practice, the two are used together. When your browser connects to a secure website (HTTPS):
- The browser and server use asymmetric encryption to agree on a secret key safely, since the public key can be sent openly (key exchange).
- They then switch to symmetric encryption, using that key (the session key) for all the rest of the conversation, because it is fast.
This gets the security of asymmetric encryption for the key exchange, and the speed of symmetric encryption for the data.
Worked example
Task: Amy wants to send Ben a private message. Describe how this works with asymmetric encryption, and why a stranger who intercepts it can't read it.
- Ben has a key pair. He publishes his public key and keeps his private key secret.
- Amy encrypts her message using Ben's public key, and sends the ciphertext.
- A stranger who intercepts it has only the ciphertext and Ben's public key. The public key can't be used to decrypt the message.
- Ben uses his private key to decrypt it. Only he has it, so only he can read the message.
If Amy and Ben used symmetric encryption instead, they would first have to agree a secret key, and sharing that key safely would be the problem.
Exam tip: state the key difference: one shared key (symmetric) against public and private key pair (asymmetric). Say that asymmetric solves the key exchange problem but is slower, and that real systems combine them.
Check yourself
What is the main difference between symmetric and asymmetric encryption?
Symmetric encryption uses the same key to encrypt and decrypt. Asymmetric encryption uses a pair of keys: a public key to encrypt and a private key to decrypt.
What is the key distribution problem?
With symmetric encryption, both parties need the same secret key, but there is no safe way to send it if someone might intercept it.
Why is asymmetric encryption not used for all data?
It is much slower and needs more processing power than symmetric encryption, so it is unsuitable for large amounts of data.
Which key does Amy use to send a secret message to Ben with asymmetric encryption?
Ben's public key. Only Ben's private key can decrypt it.