1
$\begingroup$

Is php's bin2hex(random_bytes(8)) safe for an initialization vector when using openssl_encrypt()?

$cipherText = openssl_encrypt(
    'Secret message.',
    'AES-256-CBC',
    'some key',
    OPENSSL_RAW_DATA,
    bin2hex(random_bytes(8))
);
$\endgroup$
  • $\begingroup$ Just random_bytes(16) would be secure, why do you think you need bin2hex precisely? The chance of collisions when using just 8 bytes / 64 bits is pretty high (due to the birthday problem). $\endgroup$ – Maarten Bodewes Apr 11 '17 at 21:01