Lesson 10: Symmetric Encryption: One Shared Secret
Symmetric encryption is the simplest form of modern cryptography, and it is the workhorse of the internet: one secret key is used both to encrypt a message and to decrypt it, so anyone with the key can read the message, and anyone without it cannot. It is fast, it is strong, and it protects the bulk of the data that travels across the web every day, from your messages to your bank details. Its one great problem is sharing the key: how do two people who have never met agree on a secret without anyone else learning it? This lesson explains how symmetric ciphers work, introduces AES, the standard the world uses, and shows why the key-sharing problem needs a second kind of cryptography, which is the subject of the next lesson.
How a symmetric cipher works
A modern symmetric cipher, such as AES, the Advanced Encryption Standard, works on blocks of data, scrambling each block through many rounds of substitution and mixing, where each round uses part of the key. The details of the maths are beyond this course, but the properties matter: the same key always encrypts the same plaintext to the same ciphertext, a tiny change in the key or the plaintext changes the output completely, and without the key, the ciphertext looks random and gives no clue about the message. AES comes in key sizes of 128, 192 and 256 bits, and all three are considered secure today, with 256 bits offering a margin against future computers. It is used everywhere: in messaging apps, in Wi-Fi, in disk encryption, and inside TLS, which you will meet in Lesson 12, where it does the heavy lifting of encrypting the actual data.
Modes, IVs and why the same message must look different
Encrypting a long message is not as simple as encrypting each block on its own, because identical blocks would produce identical ciphertext, which leaks information about the message, such as repeated words or patterns. The fix is to use a mode of operation that mixes the blocks together, usually by chaining them, so each block's encryption depends on the ones before it, and to start the chain with an initialisation vector, or IV, a random value that is different every time, so the same message encrypted twice looks completely different. The IV does not need to be secret, but it must be random and never reused with the same key, because reusing it undoes the protection. These details are the reason you should never try to design your own encryption: the cipher may be perfect, but a mistake in how it is used, such as a reused IV, can break the whole system, and that is a job for tested libraries, not for hand-written code.
Message authentication: proving nothing changed
Encryption alone does not prove a message is genuine, because an attacker who cannot read the ciphertext might still be able to change it, and the receiver would decrypt a corrupted message without knowing. The fix is a message authentication code, or MAC, a short tag computed from the message and the key, which the receiver recomputes and compares: if the tags match, the message is unchanged and came from someone with the key. Modern practice combines encryption and authentication into a single construction, called authenticated encryption, such as AES-GCM, which does both jobs at once and is the standard choice in TLS and in messaging apps. The lesson is that secrecy and integrity are separate jobs, and a system that only encrypts is only half a system, which is why you should look for authenticated encryption whenever you choose a tool or a library.
The key distribution problem
Symmetric encryption has one problem it cannot solve on its own: the two sides must share the key before they can talk, and sharing a secret over a channel an attacker can watch is exactly the problem encryption was meant to solve. In the past, keys were shared in person, by courier, or by phone, which works for two people who know each other but not for a browser talking to a website it has never met. The solution is asymmetric encryption, which lets two strangers agree on a shared secret in public, and that is the subject of the next lesson. In practice, the two kinds of cryptography work as a team: asymmetric cryptography sets up the secret, and symmetric cryptography does the fast, heavy work of encrypting the conversation, which is the design you will see inside TLS in Lesson 12.
Key Terms
- Symmetric encryption
- Encryption where the same secret key encrypts and decrypts, such as AES.
- AES
- Advanced Encryption Standard, the symmetric cipher used almost everywhere today.
- Block cipher
- A cipher that encrypts data in fixed-size blocks, scrambling each block through many rounds.
- Initialisation vector (IV)
- A random value that starts the encryption chain, so the same message looks different each time.
- Mode of operation
- The method for encrypting a long message, such as chaining blocks together so patterns do not leak.
- Message authentication code (MAC)
- A short tag proving a message is unchanged and came from someone with the key.
- Authenticated encryption
- Encryption that provides both secrecy and integrity at once, such as AES-GCM.
Discussion Questions
- If symmetric encryption is fast and strong, why can two strangers not just use it directly?
- Why must the same message encrypted twice look different? What would leak if it did not?
- Why should you never design your own encryption, even if you understand the maths?
Practice Questions
- What is symmetric encryption?
- What does an initialisation vector do?
- Why is encryption alone not enough to prove a message is genuine?
- What is AES, and what key sizes does it come in?
- What is the key distribution problem?
Show answers
- Encryption where the same secret key encrypts and decrypts. Anyone with the key can read the message, and anyone without it cannot.
- It makes the same message encrypt differently each time. The IV starts the encryption chain with a random value, so repeated patterns do not leak.
- Because an attacker might alter the ciphertext without reading it. A message authentication code is needed to prove the message is unchanged.
- AES is the Advanced Encryption Standard, the symmetric cipher used almost everywhere. It comes in 128, 192 and 256-bit keys, all considered secure today.
- Two sides must share a secret key before they can talk, but sharing it securely is the very problem encryption solves. Asymmetric cryptography is the usual answer.