Data Encryption at Rest and in Transit
What Is Data at Rest and Data in Transit?
Data at rest refers to information stored on a device or server, such as files on a hard drive or database records, while data in transit refers to data actively moving across a network, such as an email being sent or a file being uploaded.
Encrypting Data at Rest
Encrypting data at rest protects stored information from being read if a storage device is stolen, lost, or accessed without authorization, typically using full-disk encryption or database-level encryption.
Encrypting Data in Transit
Encrypting data in transit protects information as it travels between systems, commonly implemented using protocols like TLS, preventing attackers from intercepting and reading data while it is being transmitted.
| State | Risk if Unencrypted | Common Protection |
|---|---|---|
| At Rest | Theft of storage device, unauthorized file access | Full-disk or database encryption |
| In Transit | Interception, eavesdropping | TLS/SSL, VPN |
Why Both Are Necessary
Protecting data in only one state leaves a gap - encrypting data in transit but not at rest still leaves stored files vulnerable, and vice versa, so a complete strategy addresses both.
How Encryption at Rest Works Behind the Scenes
Most platforms use a pattern called envelope encryption. The data itself is encrypted with a data encryption key (DEK), usually a symmetric AES key, because symmetric ciphers are fast for large volumes. The DEK is then encrypted with a key encryption key (KEK) held in a key management service or hardware security module. Only the wrapped DEK is stored next to the data.
- The application or storage layer asks the key service for a new DEK.
- Data is encrypted with the DEK, and the plaintext key is wiped from memory after use.
- The encrypted DEK is saved with the data.
- To read, the system sends the wrapped DEK to the key service, which checks permissions and returns it unwrapped.
This design means rotating the master key does not require re-encrypting every file, and access to the key service can be logged and revoked separately from access to storage.
Protecting Data in Transit in Practice
For web traffic, TLS is configured on the server or load balancer. A safe baseline is to allow only modern protocol versions, redirect plain HTTP to HTTPS and tell browsers to remember that choice. An nginx example:
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/ssl/certs/example.com.fullchain.pem;
ssl_certificate_key /etc/ssl/private/example.com.key;
ssl_protocols TLSv1.2 TLSv1.3;
add_header Strict-Transport-Security "max-age=31536000" always;
}
Internal traffic matters too. Connections from an app to its database, cache or message broker should also use TLS, ideally with certificate verification turned on. You can confirm what a server actually offers with a read-only check:
openssl s_client -connect example.com:443 -servername example.com -tls1_2
Mistakes That Leave Data Exposed
- Storing encryption keys in the same place as the encrypted data, such as a config file inside the same backup.
- Disabling certificate verification in code to "fix" a connection error, which removes protection against impersonation.
- Encrypting the main database but forgetting log files, exports, temporary files and backups.
- Keeping old protocol versions enabled for a single legacy client long after it is gone.
- Never rotating keys or certificates, so a leaked key stays useful indefinitely.
| Choice | When it helps | Limitation |
|---|---|---|
| Full-disk encryption | Lost or stolen laptops and drives | No protection once the system is running and unlocked |
| Database or column encryption | Sensitive fields such as ID numbers | Adds key handling inside the application |
| Application-level encryption | Data that even admins should not read | Searching and indexing become harder |
Practical Hardening Checklist
- List where sensitive data lives, including copies and backups.
- Use a managed key service and restrict who can use each key.
- Enforce HTTPS everywhere and keep certificate renewal automated.
- Turn on TLS for service-to-service and database connections.
- Review access logs for the key service regularly and alert on unusual use.
Ready to master Cybersecurity Training Course?
Join Uncodemy's hands-on training and build real-world cybersecurity skills with expert mentors.