Weak random (ARCH4115)
هذا المحتوى غير متوفر بلغتك بعد.
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.
Incorrect
Section titled “Incorrect”String token = Long.toHexString(new Random().nextLong());Correct
Section titled “Correct”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.