title: How to securely generate an IV for AES CBC Encryption?
body: <p>I work on some crypto stuff.</p>
  <ul>
  <li>I use AES 256 with CBC mode</li>
  <li>I use OPENSSL</li>
  </ul>
  <p>I am aware of the following things (source = wikipedia):</p>
  <p>an initalization vector should be:</p>
  <ul>
  <li>Unique: must not be repeated for any message encrypted with a given key</li>
  <li>Unpredictable: an attacker who observes any number of messages and their IVs should have no information to predict the next one with probability of success greater than 50% per bit (i.e., indistinguishable from random)</li>
  </ul>
  <p>My question is, how to securely generate the IV with OPENSSL and PHP? I know there is such a functionnality in lib mcrypt (<a href="https://php.net/manual/en/function.mcrypt-create-iv.php" rel="nofollow noreferrer">https://php.net/manual/en/function.mcrypt-create-iv.php</a>)</p>
  <p>I didn't find anything for doing this with OPENSSL (generating unique and unpredictable IV).</p>