title: When Do We Need to Provide Our Own Random Initialization Vector (IV) With Android?
body: <p>There are many published reports that on older versions of Android, we need to provide our own <code>SecureRandom</code>-based initialization vector (IV), as the default ones are not random:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/29267435/generating-iv-for-aes-in-java">Generating IV for AES in Java</a></li>
  <li><a href="https://medium.com/@tiensinodev/basic-android-encryption-dos-and-don-ts-7bc2cd3335ff" rel="noreferrer">https://medium.com/@tiensinodev/basic-android-encryption-dos-and-don-ts-7bc2cd3335ff</a></li>
  <li><a href="https://tozny.com/blog/encrypting-strings-in-android-lets-make-better-mistakes/" rel="noreferrer">https://tozny.com/blog/encrypting-strings-in-android-lets-make-better-mistakes/</a></li>
  <li><a href="https://stackoverflow.com/questions/31036780/android-cryptography-api-not-generating-safe-iv-for-aes">Android cryptography API not generating safe IV for AES</a></li>
  </ul>
  
  <p>Conversely, as of API Level 23, if you try to provide your own IV, you also have to <a href="https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder.html#setRandomizedEncryptionRequired(boolean)" rel="noreferrer">call <code>setRandomizedEncryptionRequired(false)</code> on the <code>KeyGenParameterSpec.Builder</code></a>, as otherwise you get a "Caller-provided IV not permitted when encrypting" exception.</p>
  
  <p>Presumably, somewhere along the line, Android went from "awful" to "good enough" in terms of IV generation.</p>
  
  <p>What is the cutoff, below which we should generate our own IV versus use Android's generated IV?</p>