Member-only story
AES CBC vs GCM in Spring Boot: Which Mode Should You Choose?
4 min readDec 29, 2024

Encryption can be tricky in any Java-based application, including Spring Boot projects. If you’ve come across AES (Advanced Encryption Standard), you might be wondering about the difference between CBC (Cipher Block Chaining) and GCM (Galois/Counter Mode). Let’s do a quick overview, outline best practices, and highlight libraries you might use.
AES CBC (Cipher Block Chaining)
How it works
- Data is split into fixed-size blocks.
- Each block is XORed with the previous encrypted block, making it dependent on all previous blocks.
- Requires an Initialization Vector (IV) to kick things off.
- No built-in authentication — you often need an HMAC to ensure integrity.
Pros
- Widely supported and historically used in many applications.
- Straightforward to implement with standard Java libraries.
Cons
- Vulnerable to padding oracle attacks if not used correctly (e.g., no padding or partial checks).
- Lacks built-in authentication; you need an additional HMAC or MAC for integrity checks.