Ir al contenido

Weak random (ARCH4115)

Esta página aún no está disponible en tu idioma.

Key java.security.weak-random · Severity warning · Category security · CWE CWE-338

A non-cryptographic PRNG like java.util.Random produces predictable output when used for security-sensitive values such as tokens, keys, salts, or session ids.

String token = Long.toHexString(new Random().nextLong());
byte[] buf = new byte[32];
SecureRandom.getInstanceStrong().nextBytes(buf);
String token = HexFormat.of().formatHex(buf);

Use SecureRandom for all security-sensitive values; never use java.util.Random or Math.random.