Using pseudorandom number generators (PRNGs) is security-sensitive. For example, it has led in the past to the following vulnerabilities:
When software generates predictable values in a context requiring unpredictability, it may be 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.
As the java.util.Random
class relies on a pseudorandom number generator, this class and relating java.lang.Math.random()
method should not be used for security-critical applications or for protecting sensitive data. In such context, the
java.security.SecureRandom
class which relies on a cryptographically strong random number generator (RNG) should be used in place.
You are at risk if you answered yes to the first question and any of the following ones.
Random random = new Random(); // Sensitive use of Random byte bytes[] = new byte[20]; random.nextBytes(bytes); // Check if bytes is used for hashing, encryption, etc...
SecureRandom random = new SecureRandom(); // Compliant for security-sensitive use cases byte bytes[] = new byte[20]; random.nextBytes(bytes);