Ir al contenido

Static IV (ARCH7114)

Esta página aún no está disponible en tu idioma.

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.

<?php
$iv = str_repeat("\0", 16);
$ct = openssl_encrypt($plain, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
<?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 ciphertext

Generate a unique IV with random_bytes() for every encryption and store it alongside the ciphertext.