30 Mins

5. Symmetric Key Encryption (AES-256-GCM)

Introduction to Symmetric Encryption

Symmetric encryption is a cryptographic primitive where the exact same key is used for both the encryption of plaintext into ciphertext and the decryption of ciphertext back into plaintext. Because both parties must possess the same secret key, key distribution security is the primary challenge.

In a symmetric system, we take a plaintext input (P) and a key (K) and apply an algorithm to produce ciphertext (C). To retrieve the data, the operation is reversed: P = Decrypt(C, K). The security relies entirely on the secrecy of K, not the obscurity of the algorithm.

Security Operator Note: Always use a high-entropy secret key generated via a secure pseudo-random number generator (CSPRNG) rather than human-readable passwords.
Text
openssl enc -aes-256-cbc -salt -in data.txt -out data.enc -k 'super-secret-key'; openssl enc -d -aes-256-cbc -in data.enc -out decrypted.txt -k 'super-secret-key'

Stream vs Block Ciphers

Ciphers are categorized based on how they process data. Block ciphers take a fixed-size block of bits (e.g., 128-bit) and transform them using the key. Stream ciphers treat the plaintext as a continuous stream of bits, XORing them with a keystream.

Cipher TypeMechanismExamples
Block CipherProcesses fixed-size blocksAES, DES
Stream CipherProcesses bit-by-bit via XORChaCha20, RC4
Security Operator Note: Modern protocols prefer stream ciphers like ChaCha20 when performance on hardware lacking AES-NI acceleration is a requirement.
Python 3
import os; from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305; key = ChaCha20Poly1305.generate_key(); cipher = ChaCha20Poly1305(key); nonce = os.urandom(12); ciphertext = cipher.encrypt(nonce, b'Sensitive Data', None); print(f'Ciphertext (hex): {ciphertext.hex()}')

Advanced Encryption Standard (AES)

AES is the industry standard for symmetric block encryption. It operates on a fixed block size of 128 bits. The security strength is determined by the key length: 128, 192, or 256 bits. AES-256 is the gold standard for high-security environments.

The algorithm uses a substitution-permutation network. During encryption, the data undergoes multiple rounds of SubBytes, ShiftRows, MixColumns, and AddRoundKey operations. A 256-bit key involves 14 rounds of these transformations.

Security Operator Note: Never reuse the same Initialization Vector (IV) with the same key in CBC mode, as it can leak patterns in your data.
Python 3
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes; import os; key = os.urandom(32); iv = os.urandom(16); cipher = Cipher(algorithms.AES(key), modes.CBC(iv)); encryptor = cipher.encryptor(); ct = encryptor.update(b'VoidX-Data-Packet') + encryptor.finalize(); print(f'Encrypted block: {ct.hex()}')

Authenticated Encryption: AES-GCM

AES-GCM (Galois/Counter Mode) provides both confidentiality and authenticity. Unlike older modes (CBC/ECB), it detects if the ciphertext has been tampered with by including a GMAC (Galois Message Authentication Code).

GCM is classified as AEAD (Authenticated Encryption with Associated Data). This means you can authenticate cleartext data (like packet headers) alongside the encrypted payload, preventing man-in-the-middle attacks from modifying packet metadata.

Security Operator Note: AES-GCM is currently the preferred encryption mode for TLS 1.3 traffic due to its high efficiency and inherent integrity checks.
Python 3
from cryptography.hazmat.primitives.ciphers.aead import AESGCM; key = AESGCM.generate_key(bit_length=256); aesgcm = AESGCM(key); nonce = os.urandom(12); data = b'Critical Payload'; ad = b'Header-Info'; ct = aesgcm.encrypt(nonce, data, ad); print(f'Authenticated Ciphertext: {ct.hex()}')

Knowledge Check

Ready to test your understanding of 5. Symmetric Key Encryption (AES-256-GCM)?

Back