MASTG-KNOW-0013: Random number generation
Cryptography requires secure pseudo random number generation (PRNG). Standard Java classes as java.util.Random
do not provide sufficient randomness and in fact may make it possible for an attacker to guess the next value that will be generated, and use this guess to impersonate another user or access sensitive information.
In general, SecureRandom
should be used. However, if the Android versions below Android 4.4 (API level 19) are supported, additional care needs to be taken in order to work around the bug in Android 4.1-4.3 (API level 16-18) versions that failed to properly initialize the PRNG.
Most developers should instantiate SecureRandom
via the default constructor without any arguments. Other constructors are for more advanced uses and, if used incorrectly, can lead to decreased randomness and security. The PRNG provider backing SecureRandom
uses the SHA1PRNG
from AndroidOpenSSL
(Conscrypt) provider.
Check the Android Documentation for more details.