MySQL raises ER_AES_INVALID_IV (error 1882) when the initialization vector (IV) passed to AES_ENCRYPT or AES_DECRYPT is shorter than the required length for the chosen encryption mode.
ER_AES_INVALID_IV (MySQL error 1882) means the IV you supplied to AES_ENCRYPT or AES_DECRYPT is too short for the cipher mode. Provide an IV of at least 16 bytes (128 bits) - most users fix it by generating a 16-byte RANDOM_BYTES() value.
ER_AES_INVALID_IV
MySQL throws ER_AES_INVALID_IV when AES_ENCRYPT, AES_DECRYPT, or CREATE TABLE ... ENCRYPTION calls receive an initialization vector that is shorter than the cipher requires. The check was added in MySQL 5.7.4 to harden encryption routines.
The IV is a random byte string that guarantees unique ciphertexts. If it is too short, cryptographic strength drops, so MySQL blocks the request and raises error 1882 instead of continuing with weak security.
The most common trigger is passing an IV shorter than 16 bytes to AES_ENCRYPT or AES_DECRYPT while using the default 128-bit block size modes (AES-128-CBC, AES-256-CBC). Other causes include mistakenly supplying a hex value without UNHEX(), truncating the IV in application code, or reading an old IV from a column defined with the wrong length.
The error also appears when the --block-encryption-mode server variable is set to modes that require longer IVs such as AES_256_GCM and you still pass a 16-byte IV instead of the mandated 12-byte GCM nonce.
Generate an IV with the correct byte length for the encryption mode in use. For CBC modes, 16 bytes is mandatory. Use RANDOM_BYTES(16) or a cryptographically strong generator in your application, then store or transmit the IV alongside the ciphertext.
If you stored IVs in a CHAR column that is too short, migrate the column to BINARY(16) or VARBINARY(16) and update existing rows with properly sized IVs. Always verify byte length with OCTET_LENGTH().
During data migration, developers sometimes copy ciphertext into a new table but forget the IV column. The next decrypt attempt fails. Copy the IV exactly as stored at encryption time to resolve the issue.
In languages like PHP, passing a UTF-8 string directly can reduce byte length if multibyte characters are trimmed. Encode the IV with base64 or hex and convert back to raw bytes in SQL.
Always store IVs in a fixed-length BINARY column equal to the required size. Validate length in application code before executing AES_ENCRYPT. Automate generation with MySQL RANDOM_BYTES() to prevent developer errors.
When working in Galaxy, enable parameter snippets that force a 16-byte IV variable. Galaxy’s AI copilot warns if OCTET_LENGTH(iv_param) < 16 before the query runs, helping you catch mistakes early.
Error 1815 ER_BAD_CIPHER: raised when you specify an unsupported cipher name. Pick a valid value in block_encryption_mode.
Error 1556 ER_AES_INVALID_KEYSIZE: appears if the key length is not 16, 24, or 32 bytes. Generate a compliant key with RANDOM_BYTES().
Developers often provide an 8-byte or 12-byte string, forgetting CBC requires 16 bytes.
Supplying '0F0E0D0C0B0A0908' without UNHEX() results in an 8-byte literal, triggering the error.
Storing the IV in a CHAR(16) column and later converting to UTF-8 can silently cut off bytes.
Using AES_256_GCM with a 16-byte IV causes a length mismatch because GCM expects a 12-byte nonce.
Raised when an unsupported cipher name is used in block_encryption_mode.
Occurs if the key length is not 16, 24, or 32 bytes for AES.
Shows up when BLOB or TEXT column lengths exceed maximum bytes allowed.
CBC modes require exactly 16 bytes. GCM expects 12 bytes. Always match the cipher mode.
Reusing IVs weakens encryption and risks data leaks. Generate a unique IV for every encryption call.
MariaDB 10.1 and later have a similar length check, so you may see ER_AES_INVALID_IV there as well.
Galaxy’s AI copilot inspects parameters and alerts you when OCTET_LENGTH(iv) is wrong, preventing the query from running.