Encryption

A2.4.4: Encryption and digital certificates


Key Concepts

What is Encryption?

  • Encryption: the process of converting readable data (plaintext) into an unreadable format (ciphertext) using an algorithm and a key
  • Decryption: the reverse. Converting ciphertext back to plaintext using the appropriate key
  • Purpose: protect confidentiality of data in transit (over networks) and at rest (in storage)
Plaintext  →  [Encryption Algorithm + Key]  →  Ciphertext
"Hello"    →  [AES + secret key]            →  "7g$kL9..."

Ciphertext →  [Decryption Algorithm + Key]  →  Plaintext
"7g$kL9..." → [AES + secret key]            →  "Hello"

Symmetric Encryption

  • Same key is used for both encryption and decryption
  • Also called “secret key” or “shared key” encryption
  • Fast and efficient for large amounts of data

How it works:

sequenceDiagram
    participant S as Sender
    participant R as Receiver
    Note over S,R: Both hold the SAME secret key
    Note over S: Encrypts the plaintext with the key
    S->>R: Ciphertext
    Note over R: Decrypts it with the same key

Examples:

  • AES (Advanced Encryption Standard): 128-, 192- or 256-bit keys; current industry standard; used for file encryption, disk encryption, VPNs
  • DES (Data Encryption Standard): 56-bit key; historical, now insecure (can be brute-forced in hours); replaced by AES

Key distribution problem: the biggest challenge with symmetric encryption is securely sharing the key. If you encrypt a file with a secret key and want to send it to someone, you need to somehow get the key to them securely. If you send the key over the same insecure channel, an attacker could intercept it. This is why asymmetric encryption was developed.

Advantages and disadvantages:

Advantages Disadvantages
Fast: efficient for encrypting large volumes of data Key distribution problem: how to share the key securely?
Simple algorithm: less computationally expensive If the key is compromised, all data encrypted with it is exposed
Suitable for encrypting stored data (at rest) Each pair of communicators needs a unique key (n users need n(n-1)/2 keys)

Asymmetric Encryption

  • Uses a pair of keys: a public key (shared openly) and a private key (kept secret)
  • Also called “public key” encryption
  • Slower than symmetric but solves the key distribution problem

How it works: Encryption for confidentiality:

sequenceDiagram
    participant S as Sender
    participant R as Receiver
    Note over S: Encrypts the plaintext<br/>with the receiver's PUBLIC key
    S->>R: Ciphertext
    Note over R: Decrypts it with the receiver's PRIVATE key,<br/>which only the receiver holds

Key principle: What is encrypted with the public key can ONLY be decrypted with the matching private key. What is encrypted with the private key can ONLY be decrypted with the matching public key. The private key must never be shared.

How it works: Digital signatures (proving identity):

sequenceDiagram
    participant S as Sender
    participant R as Receiver
    Note over S: Hashes the message, then encrypts the hash<br/>with the sender's PRIVATE key: the digital signature
    S->>R: Message + digital signature
    Note over R: Decrypts the signature with the sender's PUBLIC key<br/>and hashes the received message
    Note over R: The two hashes match:<br/>the message is authentic and unaltered

Advantages and disadvantages:

Advantages Disadvantages
Solves key distribution problem: public key can be freely shared Slower than symmetric encryption
Enables digital signatures (proving identity) Computationally expensive for large data
No need to exchange secret keys in advance Key pairs must be managed carefully

In practice, both are used together: Asymmetric cryptography is used to set up a shared symmetric key securely (by sending it encrypted, or by agreeing it from values each side contributes), then the symmetric key is used for the actual data encryption (because it is faster). This is exactly what happens in an SSL/TLS handshake.

The Internet: Encryption & Public Keys - Code.org
The Internet: Encryption & Public Keys - Code.org

How symmetric and asymmetric encryption protect data, with a clear public/private key demonstration.

Watch on YouTube

Digital Signatures

  • A digital signature proves:
    1. Authentication: the message really came from the claimed sender
    2. Integrity: the message has not been altered in transit
    3. Non-repudiation: the sender cannot deny having sent the message

How digital signatures work:

  1. Sender creates a hash (fixed-length fingerprint) of the message
  2. Sender encrypts the hash with their private key: this is the digital signature
  3. Sender sends both the message and the digital signature
  4. Receiver decrypts the signature with the sender’s public key to get the hash
  5. Receiver independently hashes the received message
  6. If the two hashes match: message is authentic and unaltered

Digital Certificates

  • A digital certificate is an electronic document that verifies the identity of a website, server, or individual
  • Issued by a trusted third party called a Certificate Authority (CA) (e.g., Let’s Encrypt, DigiCert, Sectigo)
  • Contains: the certificate holder’s name, their public key, the CA’s digital signature, expiry date

Purpose:

  • When you visit an HTTPS website, the server presents its digital certificate
  • Your browser checks: (1) Is the certificate issued by a trusted CA? (2) Has it expired? (3) Does the domain match?
  • If valid, the browser trusts the server’s public key and establishes a secure connection
  • Think of it as a digital “ID card”, just as a passport is issued by a government to verify identity, a digital certificate is issued by a CA to verify a server’s identity

Without digital certificates, an attacker could impersonate any website by presenting a fake public key. Certificates ensure you are communicating with the genuine server, not an impersonator (preventing MitM attacks).

SSL/TLS Handshake (Simplified)

SSL (Secure Sockets Layer) and its successor TLS (Transport Layer Security) establish secure HTTPS connections. Here is a simplified version of the handshake:

sequenceDiagram
    participant B as Browser
    participant W as Web server
    B->>W: 1. Hello, with the ciphers it supports
    W->>B: 2. Server certificate, with the server's public key
    Note over B: 3. Verifies the certificate<br/>(CA signature, expiry)
    Note over B: 4. Generates a session key and encrypts it<br/>with the server's public key
    B->>W: 4. Encrypted session key
    Note over W: 5. Decrypts the session key<br/>with its private key
    B->>W: 6. Data encrypted with the shared session key (AES)
    W->>B: 6. Data encrypted with the shared session key (AES)

The SSL/TLS handshake uses asymmetric cryptography (public/private keys) to prove the server’s identity and to get a symmetric session key set up securely. All subsequent data is encrypted with the symmetric key because it is much faster. This combines the security of asymmetric with the speed of symmetric.

What this diagram shows: a simplified key-transport model, the version the exercises on this page use. It matches older TLS versions, which used RSA key exchange. Modern TLS (version 1.3) keeps steps 1 to 3, so the certificate still proves the server’s identity, but it no longer sends the session key across the network. Instead, the browser and the server each send a temporary public value and both calculate the same session key from them (a key agreement, such as Diffie-Hellman). Because the session key was never encrypted with the server’s long-term private key, someone who steals that key later cannot decrypt recorded past sessions. This property is called forward secrecy. Where a question asks about HTTPS or TLS in general, either description is a correct answer.

SSL, TLS, HTTP, HTTPS Explained - PowerCert
SSL, TLS, HTTP, HTTPS Explained - PowerCert

Visual breakdown of the SSL/TLS handshake and why HTTPS is essential for secure web browsing.

Watch on YouTube

Key Management

Why key management matters:

  • If a private key is stolen, an attacker can impersonate the key owner and decrypt anything that was encrypted directly with the matching public key. How much past traffic that exposes depends on how the key was used: in the simplified handshake above it would include recorded session keys, whereas modern TLS’s temporary keys keep past sessions safe (forward secrecy)
  • If a symmetric key is compromised, all data encrypted with it is exposed
  • Keys should be stored securely (hardware security modules, encrypted keystores)
  • Keys should be rotated regularly (replaced with new keys periodically)
  • Expired or compromised certificates must be revoked immediately

Risks of poor key management:

  • Stolen keys: data breaches, identity theft
  • Lost keys: permanent loss of encrypted data
  • Expired certificates: browser warnings, loss of user trust
  • Weak keys: vulnerable to brute-force attacks

Enrichment: Frequency Analysis

This goes beyond the IB syllabus, so it is not assessed.

Frequency analysis is a technique for breaking simple substitution ciphers. In English, the most common letter is ‘e’ (~13% of all text). If the most common letter in the ciphertext is ‘x’, the cipher likely maps e → x. This technique can crack historical ciphers (like Caesar cipher) but is ineffective against modern encryption algorithms like AES, which produce output that appears random.

Enrichment: Authentication Factors

This goes beyond the IB syllabus, so it is not assessed.

Authentication factors (used in MFA):

  • Something you know: password, PIN, security question
  • Something you have: phone (SMS code), security token, smart card
  • Something you are: fingerprint, face recognition, iris scan (biometrics)

MFA combines two or more of these categories (using exactly two is called 2FA). Using two passwords is NOT MFA: both are “something you know.”


Worked Examples

Example 1: Symmetric vs Asymmetric Scenarios

# Scenario Encryption Type Explanation
1 Encrypting files on your own hard drive Symmetric Only you need the key; no distribution problem; speed matters
2 Sending a confidential email to a colleague Asymmetric Encrypt with recipient’s public key; no need to share a secret
3 Establishing an HTTPS connection Both Asymmetric handshake exchanges a symmetric session key
4 Signing a software update to prove it is genuine Asymmetric Developer signs with private key; users verify with public key
5 VPN tunnel encrypting all traffic Symmetric (after key exchange) Asymmetric used for initial key exchange; symmetric for speed

Example 2: SSL/TLS Handshake Walkthrough

Trace what happens when a student visits https://school.edu, using the simplified key-transport model from the diagram above:

Step Action Encryption Used Key
1 Browser sends “Hello” to school.edu None -
2 Server sends its digital certificate (including public key) None Server’s public key is in the certificate
3 Browser checks the CA’s signature on the certificate None CA’s public key (pre-installed in browser)
4 Browser generates random session key - New symmetric key
5 Browser encrypts session key and sends it Asymmetric Server’s public key encrypts the session key
6 Server decrypts session key Asymmetric Server’s private key
7 All subsequent traffic Symmetric Shared session key (AES)

Quick Check

Q1. In symmetric encryption, how many keys are used?

Q2. What is the main advantage of asymmetric encryption over symmetric encryption?

Q3. What does a digital certificate verify?

Q4. In the simplified SSL/TLS handshake on this page, the browser generates a session key and encrypts it with the server's _____ key.

Q5. Why is key management important?


Trace the Handshake

Trace the SSL/TLS handshake process. For each step, fill in what is sent or what happens.

Trace: SSL/TLS Handshake

A browser connects to a web server over HTTPS. Fill in the key action at each step of the simplified key-transport handshake shown on this page.

StepActorActionWhat happens
1 Browser Initiates connection
2 Server Responds
3 Browser Validates
4 Browser Key exchange
5 Server Decryption

Spot the Error

A student wrote revision notes about encryption. One line contains an error. Select the line with the error, then pick the correct fix.

1Symmetric: uses two different keys (a public key and a private key) 2Asymmetric: uses a key pair where the public key encrypts and the private key decrypts 3Digital certificates: issued by a Certificate Authority to verify identity 4SSL/TLS: uses asymmetric encryption for the handshake, then a symmetric session key for the data

Pick the correct fix for line 1:


Fill in the Blanks

Complete the summary of encryption by filling in the correct term for each blank.

Fill in the blanks to complete this summary of encryption:

ENCRYPTION
==========
 encryption uses the same key for both encryption and decryption.

 encryption uses a public key and a private key pair.

A  is issued by a Certificate Authority to verify a server's identity.

In the simplified SSL/TLS handshake on this page, the browser encrypts a session key using the server's  key.

 is the current industry standard for symmetric encryption, using 128-, 192- or 256-bit keys.

Predict the Output

Alice encrypts a message using Bob's public key. Can Alice decrypt the message she just encrypted? (Type Yes or No)

A company uses symmetric encryption with a unique key for each pair of employees. If there are 10 employees, how many unique keys are needed? (Use the formula n(n-1)/2. Type a number)


Practice Exercises

Core

  1. Encryption Basics: Explain the difference between symmetric and asymmetric encryption. For each, give one advantage and one disadvantage.

  2. Digital Certificates: Describe what a digital certificate is, who issues it, and why it is important for secure web browsing. What would happen if digital certificates did not exist?

  3. Key Concepts: Define the following terms: plaintext, ciphertext, encryption key, decryption, Certificate Authority.

Extension

  1. SSL/TLS Walkthrough: Describe the steps of the SSL/TLS handshake when a user visits an HTTPS website. Explain why both symmetric and asymmetric encryption are used in this process (rather than just one type).

  2. Key Management: Explain why key management is critical for security. Describe three risks of poor key management and for each, suggest a preventive measure.

Challenge

  1. Encryption System Design: A hospital needs to implement encryption for: (a) patient records stored on servers, (b) emails between doctors discussing patient care, (c) a patient portal accessed via web browsers. For each, recommend the type of encryption and explain your choice. Consider key management, performance, and the sensitivity of the data. Evaluate the trade-offs of your design.

Connections

  • Prerequisites: Network Security: encryption is a key countermeasure against data interception and MitM attacks
  • Prerequisites: Protocols and Layers: HTTPS uses SSL/TLS encryption; understanding protocols contextualises why encryption is needed
  • Related: OS Fundamentals: OS security functions include encryption for stored data and authentication
  • Related: Number Systems: binary representation underpins how encryption keys and algorithms work at the bit level

© EduCS.me. A resource hub for Computer Science education. EduCS is an independent educational resource. It is not affiliated with, or endorsed by, the International Baccalaureate Organization. Contact