Encryption In Transit And In Rest

At Tom’s IT Cafe we break down the hard stuff so you can secure your
systems without getting lost in jargon. Below is a straight-ahead look
at what “in transit” and “in rest” mean, why they matter, and how to
implement them with the most common algorithms.

1. What Does Encryption Protect?

Encryption hides data from anyone who shouldn’t see it.

  • In transit: While data moves over a network (e.g., HTTP requests,

VPN tunnels).

  • In rest: When data sits on disk, in backups, or in cloud storage.

Both are essential. A breach of either can expose passwords, credit
cards, or intellectual property.

2. Encryption In Transit

2.1 How It Works

When a client talks to a server, they perform a handshake to agree on
encryption parameters:

  1. Client Hello – Sends supported TLS version and cipher suites.
  2. Server Hello – Chooses the best suite it supports.
  3. Certificate exchange – Server presents its public-key
    certificate.
  4. Key agreement – Diffie–Hellman or ECDHE establishes a shared
    secret.
  5. Finished messages – Both sides confirm integrity.

Once the handshake finishes, all data is encrypted with symmetric keys
derived from that shared secret.

2.2 Common Algorithms

CategoryAlgorithmWhy It’s Popular
TLS 1.3 cipher suitesTLSAES128GCMSHA256TLSAES256GCMSHA3841-RTT handshake with optional 0-RTT for resumed sessions; forward secrecy (FS)
Key exchangeECDHE-P-256, ECDHE-P-384Fast and FS; curves chosen by NIST or curve25519 for better performance.
HashingSHA-256, SHA-384Standardised, collision-resistant.
MAC (TLS 1.2)HMAC-SHA-256Still used where TLS 1.3 isn’t available.

Tip: Disable older suites such as RC4, DES, or any with NULL cipher.

2.3 Practical Implementation

Web Server (NGINX)

ssl_protocols TLSv1.3;
ssl_prefer_server_ciphers off;   # let client decide in TLS 1.3

# Modern cipher suites only
ssl_ciphers 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256';

# Enforce HSTS (HTTP Strict Transport Security)
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;

VPN (OpenVPN)

proto udp
port 1194

dev tun
ca ca.crt
cert server.crt
key server.key
dh none            # use ECDHE
tls-version-min 1.2
cipher AES-256-GCM
auth SHA256

2.4 Best Practices

ActionWhy
Use TLS 1.3 everywhereRemoves handshake complexity and supports FS by default.
Enable HSTS and HTTP/2Forces secure connections and improves performance.
Rotate certificates regularlyLimits damage if a key is compromised.
Store private keys in HSM or TPMProtects the most sensitive material.

3. Encryption In Rest

3.1 How It Works

Data at rest encryption protects files, databases, or block devices by
converting plaintext into ciphertext using a symmetric key (e.g., AES).
The key must be stored separately from the encrypted data to avoid “key
in the same place as data” vulnerabilities.

3.2 Common Algorithms

LayerAlgorithmTypical Use
Full-disk encryptionLUKS / dm-crypt with AES-256-GCMLinux servers, laptops
File system encryptioneCryptfs, Btrfs subvolume encryptionUser data on shared drives
Database column/row encryptionAES-256-GCM or 3DES (legacy)Sensitive fields in MySQL/PostgreSQL
Cloud storageSSE-S3, KMS-managed keysAWS S3, Azure Blob

Why AES-256-GCM? It provides confidentiality and integrity with
minimal overhead.

3.3 Practical Implementation

LUKS on Linux

# Create a partition (replace /dev/sdb1)
cryptsetup luksFormat /dev/sdb1
cryptsetup open /dev/sdb1 cryptroot
mkfs.ext4 /dev/mapper/cryptroot
mount /dev/mapper/cryptroot /mnt/data

PostgreSQL column encryption

-- Enable pgcrypto extension
CREATE EXTENSION IF NOT EXISTS pgcrypto;

-- Create table with encrypted field
CREATE TABLE users (
    id serial PRIMARY KEY,
    username text,
    ssn bytea   -- stored encrypted
);

-- Insert data
INSERT INTO users (username, ssn)
VALUES ('alice', pgp_sym_encrypt('123-45-6789', 'secretkey'));

-- Decrypt data
SELECT pgp_sym_decrypt(ssn, 'secretkey') FROM users;

AWS S3 Server-Side Encryption

aws s3 cp localfile.txt s3://mybucket/remote.txt --sse AES256
# or use KMS keys
aws s3 cp localfile.txt s3://mybucket/remote.txt --sse aws:kms --sse-kms-key-id alias/mykey

3.4 Key Management

OptionDescription
Hardware Security Module (HSM)Physical device that stores keys and performs crypto ops.
Cloud KMSManaged key service with audit logs, rotation APIs.
Software VaultHashiCorp Vault or similar; secure API for dynamic secrets.

Key Rotation: Change keys every 90–180 days. Automate via scripts or
built-in cloud tooling.

3.5 Best Practices

PracticeRationale
Use strong, unique keys per device/serviceLimits blast radius if a key leaks.
Separate key storage from data locationPrevents “key and ciphertext in the same breach”.
Enable audit logging for key accessDetect unauthorized reads/writes early.
Apply least-privilege to encryption servicesOnly necessary users or processes can decrypt.

4. Common Pitfalls & How to Avoid Them

MistakeImpactFix
Leaving default TLS ciphers enabledVulnerable to downgrade attacksExplicitly list modern suites; disable TLS 1.0/1.1
Using weak key sizes (e.g., 128-bit) for highly sensitive dataFuture-proofing riskPrefer 256-bit keys where performance permits
Storing encryption keys on the same server as encrypted dataSingle point of compromiseUse HSM, TPM, or cloud KMS
Not rotating keysLong exposure if a key leaksAutomate rotation; monitor for anomalies

5. Quick Reference Checklist

  1. Transit
    • TLS 1.3 only? ✔️
    • Strong cipher suites? ✔️
    • HSTS enabled? ✔️
  1. Rest
    • Full-disk encryption on all servers? ✔️
    • Database field encryption for PII? ✔️
    • Keys in HSM or cloud KMS? ✔️
  2. Ops
    • Certificate rotation schedule defined? ✔️
    • Key rotation policy automated? ✔️
    • Audit logs reviewed monthly? ✔️

Final Thought

Encryption is not a one-time checkbox; it’s an ongoing process that
blends technology, policy, and vigilance. By hardening both transit and
rest paths with proven algorithms and disciplined key management, you
protect data from the moment it leaves your application to when it sits
idle on disk.

That’s all for today! For deeper dives into specific tools or scripting
tips, keep an eye on Tom’s IT Cafe – we’ll be back soon with more
practical guides.

Leave a comment