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$

closed as off-topic by Maarten Bodewes, e-sushi Apr 12 '17 at 14:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions are off-topic even if you are writing or debugging cryptographic code. Unless your question is specifically about how the cryptographic algorithm or protocol works, you should look into asking on Stack Overflow instead." – Maarten Bodewes, e-sushi
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\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