Overview

5 Advanced Encryption Standard

Advanced Encryption Standard (AES) is the de facto symmetric block cipher used across operating systems, cloud providers, and Internet protocols to protect confidentiality. It encrypts fixed-size 128-bit blocks (with padding as needed) using a shared secret key and supports 128-, 192-, and 256-bit key sizes, with AES-256 often chosen for long-term assurance and regulatory needs. Because AES is a block cipher, applications must select a mode of operation to process data larger than a single block, and security depends critically on choosing and configuring that mode correctly.

Not all modes are safe: Electronic Codebook (ECB) is deterministic and leaks patterns, and Cipher Block Chaining (CBC) hides patterns but delivers confidentiality only, leaving data vulnerable to undetected tampering. Real-world systems need authenticated encryption—confidentiality, integrity, and authenticity—which AES-Galois/Counter Mode (GCM) provides by combining encryption with an authentication tag. AES-GCM also supports AEAD, allowing developers to bind unencrypted context (headers, database identifiers) to the ciphertext so swaps or header modifications are detected. The chief pitfall is nonce/IV reuse: with the same key, reusing a nonce in GCM is catastrophic, so each encryption must use a fresh, unpredictable 96-bit IV.

Practically, developers should default to AES-GCM (or a safer-against-reuse variant like AES-GCM-SIV), use 256-bit keys, generate keys and IVs with a cryptographically secure RNG, never reuse an IV with a given key, and use a 128-bit authentication tag. Treat decryption failures as security events, compress data before encrypting, and respect limits such as the ~68GB per key/IV bound in GCM. Java offers first-class AES-GCM support, but to avoid subtle mistakes, prefer well-vetted libraries (e.g., Google Tink) and secure key management (vaults rather than source code or configs). While quantum computing could reduce effective key strength in theory, robust implementations, proper key handling, and authenticated modes remain the decisive factors for strong, developer-friendly encryption today.

A cipher consists of an algorithm for encrypting and decrypting data using a key. The details of encryption and decryption algorithm are public knowledge while the key is kept secret. If the same key is used to encrypt and decrypt the cipher is called a symmetric cipher otherwise it is called an asymmetric cipher.
AES is a block cipher because it requires its input be a fixed size 128-bits long. AES is a symmetric cipher because the key used to encrypt is the key used to decrypt.
The Electronic Codebook Operating (ECB) Mode encrypt each input block independently using the secret key, concatenates the resulting cipher text. ECB mode is simple, but it is insecure, never use ECB mode.
The symbol with + inside a circle is the XOR operation. Cipher Block Chaining (CBC) takes the output of one block and feeds it into the next block. The net result is that even if you encrypt the same data multiple times the cipher text looks random. An attacker cannot determine any patterns in the underlying data by looking for patterns in the cipher text.
AES in CBC mode can be visualized as a black box that takes three inputs: plain text, key, and initialization vector. The initialization vector is written out as a plain text to output followed by the cipher text computed by the AES in CBC mode. Decryption process requires three inputs: initialization vector, cipher text, and key. The initialization vector and cipher text can be read from the output bytes, while the key must be provided by the party performing the decryption.
AES in GCM mode as a black box that processes three inputs: plaintext, key, and initialization vector. The algorithm outputs the initialization vector (written in plaintext), followed by the ciphertext it computes, and finally the authentication code generated by GCM mode. To decrypt, you provide four inputs: the initialization vector, ciphertext, key, and authentication code. The algorithm uses these inputs to verify the data’s integrity and recover the original plaintext.
ACME Inc. staff approve refunds using the warehouse management application. Once a day the warehouse management application generates a refunds.json file. The payment service refunds customer credit cards for the amount specified in the refunds.json file.
A message with a plain text header and an encrypted body is very common.
AES in GCM mode can be visualized as a black box that takes four inputs: plain text, secret key, initialization vector, and optional Additional Associated Data (AAD). The authentication tag is computed using the AAD data and the cipher text. The initialization vector, cipher text, and authentication tag are saved to the output. To decrypt you must provide both the encryption key, and the AAD data otherwise an error is raised.

Summary

  • Advanced Encryption Standard (AES) is the most widely used symmetric encryption algorithm, supported by all major cloud providers and operating systems for protecting data confidentiality.
  • AES is a block cipher that encrypts fixed 128-bit blocks and requires a mode of operation to handle data larger than one block.
  • Electronic Code Book (ECB) mode is insecure because identical plaintext blocks produce identical ciphertext blocks, revealing patterns to attackers.
  • Cipher Block Chaining (CBC) mode chains blocks together using initialization vectors to prevent pattern detection but only provides confidentiality, not integrity or authenticity.
  • Initialization vectors must be random, unique for each encryption operation, and never reused with the same key to prevent catastrophic security failures.
  • Authenticated encryption combines encryption with message authentication to provide confidentiality, integrity, and authenticity in a single operation.
  • Galois Counter Mode (GCM) is the recommended AES mode because it provides authenticated encryption, ensuring confidentiality, integrity, and authenticity simultaneously.
  • AES-GCM requires a secret key, random initialization vector, and produces ciphertext with an authentication tag that detects any tampering.
  • Authenticated Encryption with Associated Data (AEAD) allows plaintext headers to be authenticated along with encrypted message bodies without encrypting the headers.
  • Java provides AES support through the Cipher class, but developers should use cryptographically secure random number generators and follow specific configuration requirements.
  • Best practices include using 256-bit keys, 96-bit initialization vectors, 128-bit authentication tags, and never reusing initialization vectors.
  • Compression should be applied before encryption because encrypted data appears random and cannot be effectively compressed.
  • Quantum computers could theoretically halve AES key strength using Grover's algorithm, making 256-bit keys equivalent to current 128-bit security.
  • Developer-friendly libraries like Google Tink are recommended over hand-coding AES implementations to avoid common security mistakes.

FAQ

What is AES and why is it widely used?AES is a symmetric block cipher with a 128-bit block size and key sizes of 128, 192, or 256 bits. It’s fast, hardware-accelerated on modern CPUs, and secures protocols and systems like TLS, IPsec, SSH, and disk encryption across Windows, Linux, macOS, and major cloud providers.
What is a “mode of operation,” and why does it matter for AES security?A mode of operation defines how AES processes data larger than 16 bytes. Security depends heavily on the chosen mode: some (like ECB) are insecure, while authenticated modes like GCM provide confidentiality, integrity, and authenticity.
Why should I never use AES in ECB mode?ECB encrypts each block independently, so identical plaintext blocks produce identical ciphertext blocks. This leaks patterns and enables attacks based on repetition. Avoid ECB entirely except for decrypting legacy data to re-encrypt safely.
How does CBC mode work, and what are its limitations?CBC XORs each plaintext block with the previous ciphertext block and requires a fresh, random 128-bit IV per encryption. The IV is stored in clear. CBC provides confidentiality only; it is vulnerable to undetected tampering and offers no integrity or authenticity.
What extra guarantees does AES-GCM provide over AES-CBC?AES-GCM is an authenticated-encryption mode (AEAD) that provides confidentiality, integrity, and authenticity via an authentication tag. Decryption verifies the tag first and fails if data was altered.
What are the best practices for nonces/IVs in AES-GCM?Use a 96-bit (12-byte) IV generated with a cryptographically secure RNG for every encryption, never reuse an IV with the same key, and include the IV alongside the ciphertext. Reuse is catastrophic in GCM.
Which AES key size should I choose, and how do quantum computers affect that choice?AES-128 is strong for most uses, but AES-256 is recommended for long-term/confidence or compliance. Under Grover’s algorithm, effective strength halves (128→~64, 256→~128), so 256-bit keys provide a larger safety margin.
What pitfalls should Java developers avoid when implementing AES?- Use java.security.SecureRandom (not java.util.Random) for keys/IVs - Prefer "AES/GCM/NoPadding" with a 128-bit tag - Never reuse IVs; track or regenerate per operation - Don’t truncate tags or mix up AAD - Don’t share a Cipher instance across threads - Limit data per (key, IV) to about 68 GB - Store keys in a secure vault, not code or configs
What is AEAD and when should I use AAD with AES-GCM?AEAD binds plaintext “associated data” (like headers) to the ciphertext so tampering or swapping is detected. Provide headers as AAD during encryption; the same AAD is required for decryption or verification fails.
Should I hand-roll AES code or use a high-level library?Use a vetted library (e.g., Google Tink). It enforces safe defaults (key sizes, IV handling, tag sizes, AEAD), reduces misuse risk, and simplifies correct, portable implementations.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Software Security for Developers ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Software Security for Developers ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Software Security for Developers ebook for free