Static IV (ARCH4114)
Ce contenu n’est pas encore disponible dans votre langue.
Key java.security.static-iv · Severity error · Category security · CWE CWE-329
A hardcoded or zero IV/nonce destroys semantic security in CBC, CTR, and GCM modes; the same plaintext always produces the same ciphertext and patterns leak.
Incorrect
Section titled “Incorrect”byte[] iv = new byte[16]; // all zerosCipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");c.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));Correct
Section titled “Correct”byte[] iv = new byte[16];SecureRandom.getInstanceStrong().nextBytes(iv);Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");c.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));Generate a unique, random IV with SecureRandom for each encryption and store it alongside the ciphertext.