Static IV (ARCH7114)
هذا المحتوى غير متوفر بلغتك بعد.
Key php.security.static-iv · Severity error · Category security · CWE CWE-329
A fixed or zero IV/nonce destroys the semantic security of CBC/CTR/GCM modes: the same plaintext always produces the same ciphertext and patterns leak. A random IV must be generated for each encryption.
Incorrect
Section titled “Incorrect”<?php$iv = str_repeat("\0", 16);$ct = openssl_encrypt($plain, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);Correct
Section titled “Correct”<?php$len = openssl_cipher_iv_length('aes-256-cbc');$iv = random_bytes($len);$ct = openssl_encrypt($plain, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);$out = $iv . $ct; // store the IV alongside the ciphertextGenerate a unique IV with random_bytes() for every encryption and store it alongside the ciphertext.