# Topic 13: Encryption
**Encryption** is the process of converting readable data (plaintext) into an unreadable format (ciphertext) using an algorithm and a cryptographic key. Only parties holding the correct key can decrypt the ciphertext back into plaintext. Encryption is a fundamental software control used to guarantee data confidentiality.
---
## Differentiating Encryption States
For VCE Software Development, you must understand how encryption protects data in different states:
```
┌───────────────────────────────────────────────┐
│ ENCRYPTION │
└───────────────────────┬───────────────────────┘
│
┌───────────────────────┴───────────────────────┐
│ │
┌──────────▼──────────┐ ┌──────────▼──────────┐
│ In Transit │ │ At Rest │
└──────────┬──────────┘ └──────────┬──────────┘
│ │
* HTTPS / TLS / SSH * Database encryption (AES-256)
* Protects data moving * Protects stored data
across networks on disks/clouds
```
### 1. Encryption in Transit (Data moving over networks)
![[image-4 3.png]]
* **Purpose**: Protects data as it travels between devices (e.g., from a customer's web browser to a backend API server).
* **Protocols**: HTTPS (Hypertext Transfer Protocol Secure), TLS (Transport Layer Security), SSH (Secure Shell), and SFTP (Secure File Transfer Protocol).
* **Threat Mitigated**: Man-in-the-Middle (MitM) attacks and packet sniffing. If an attacker intercepts the data packets, they will only see encrypted gibberish.
### 2. Encryption at Rest (Data stored on hardware)
![[image-5 3.png]]
* **Purpose**: Protects data stored permanently on physical media (e.g., databases, solid-state drives, backup tapes, cloud storage).
* **Algorithms**: AES-256 (Advanced Encryption Standard).
* **Threat Mitigated**: Physical theft of server hard drives or unauthorized access to backend storage. Even if an attacker copies the raw database files, they cannot read the records without the decryption key.
---
## Key Cryptographic Concepts
* **Symmetric Encryption**: Uses the **same key** for both encryption and decryption (e.g., AES). It is fast and efficient for encrypting large amounts of data, but key sharing must be handled securely.
* **Asymmetric Encryption**: Uses a **key pair** consisting of a public key (which anyone can use to encrypt data) and a private key (held secretly by the recipient to decrypt data) (e.g., RSA, ECC). It is used for establishing secure connections (TLS handshakes) and SSH logins.
* **One-Way Hashing**: Unlike encryption, hashing is a **one-way process** that cannot be reversed. Input data (plaintext passwords) is passed through a hashing algorithm (like `bcrypt` or `Argon2`) to generate a fixed-size string (hash). When logging in, the entered password is hashed and compared to the stored hash. This ensures passwords are never stored in cleartext.
*![[image-6 3.png]]
---
## Classification of Encryption Controls
| Control Type | Examples in Encryption |
| :-------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Software Controls (Technical)** | * Forcing TLS/HTTPS for web servers.<br>* Implementing salted hashing (e.g., `bcrypt`) for user passwords. |
| **Administrative Controls** | * Key Rotation Policy (mandating keys be changed every 12 months).<br>* Guidelines prohibiting storing cryptographic keys in the same directory as the encrypted data.<br>* Strict rules regarding access to decryption keys. |
---
## VCE Exam Practice
### Scenario
*MedRecord* develops an application that stores patient medical histories. An attacker exploits a vulnerability in their cloud configuration and downloads the raw database files. Because MedRecord stored all database records in cleartext, the attacker immediately leaks the names, medical histories, and medications of 5,000 patients online.
### Questions
1. **Define** the term 'encryption'. *(1 mark)*
2. **Distinguish** between encryption 'in transit' and encryption 'at rest', using examples. *(2 marks)*
3. **Propose and justify** two software controls MedRecord should implement to protect their patient data using cryptography. *(4 marks)*
---
> [!NOTE]
> **Suggested Answers:**
> 1. *Encryption is the process of using an algorithm and a cryptographic key to encode plaintext data into an unreadable ciphertext format to prevent unauthorized access.*
> 2. *Encryption in transit protects data while it is actively traveling across a network (e.g., using HTTPS to secure medical inputs sent from a user's web browser), whereas encryption at rest protects data stored statically on physical media (e.g., using AES-256 to encrypt database files stored on cloud servers).*
> 3. * *Control 1: Database Encryption (Encryption at Rest)*. Encrypt the database tables using AES-256. This ensures that even if hackers bypass cloud configurations and steal the raw database files, the data remains unreadable without the decryption key.
> * *Control 2: Strong Password Hashing*. Implement `bcrypt` or `Argon2` hashing for all user and doctor passwords. This ensures that if the database is compromised, the actual passwords cannot be decrypted, preventing attackers from hijacking user accounts.*