IV Transmission and Storage
What You'll Learn
You'll learn how to safely send IVs alongside encrypted data and understand why IVs don't need to be kept secret.
The Core Idea
When you encrypt data with modes like CBC or CTR, you need an IV (initialization vector) or nonce. Here's the critical insight: the recipient needs that exact same IV to decrypt your message. But how do they get it?
The good news: IVs don't need to be secret. They only need to be unpredictable and unique. This means you can safely send the IV in plaintext right alongside your ciphertext.
Common Encoding Patterns
Prepending the IV
The most common approach is to simply stick the IV at the beginning of your ciphertext:
[IV][Ciphertext]
For example, with AES-CBC (16-byte IV):
- Generate random 16-byte IV
- Encrypt your message → ciphertext
- Send: IV + ciphertext as one blob
The receiver reads the first 16 bytes (the IV), then uses it to decrypt the remaining bytes (the ciphertext).
Why This Works
Think of the IV like an envelope's postmark. Everyone can see it, but it doesn't reveal the letter's contents. The attacker seeing your IV learns nothing about your encrypted message—the security comes from your secret key, not from hiding the IV.
Storage Considerations
When storing encrypted data (like in a database), use the same pattern: store IV and ciphertext together, or in adjacent fields. Just ensure you can reliably retrieve the correct IV for each ciphertext blob.
Key Takeaway: Always transmit or store the IV with its corresponding ciphertext—prepending is standard. IVs are public values; their secrecy isn't required for security, only their uniqueness and unpredictability matter.