There are many published reports that on older versions of Android, we need to provide our own SecureRandom
-based initialization vector (IV), as the default ones are not random:
- Generating IV for AES in Java
- https://medium.com/@tiensinodev/basic-android-encryption-dos-and-don-ts-7bc2cd3335ff
- https://tozny.com/blog/encrypting-strings-in-android-lets-make-better-mistakes/
- Android cryptography API not generating safe IV for AES
Conversely, as of API Level 23, if you try to provide your own IV, you also have to call setRandomizedEncryptionRequired(false)
on the KeyGenParameterSpec.Builder
, as otherwise you get a "Caller-provided IV not permitted when encrypting" exception.
Presumably, somewhere along the line, Android went from "awful" to "good enough" in terms of IV generation.
What is the cutoff, below which we should generate our own IV versus use Android's generated IV?