Security beginner

Strong random generation

Get the platform's strongest SecureRandom implementation.

✕ Java 8
// Default algorithm — may not be
// the strongest available
SecureRandom random =
    new SecureRandom();
byte[] bytes = new byte[32];
random.nextBytes(bytes);
✓ Java 9+
// Platform's strongest algorithm
SecureRandom random =
    SecureRandom.getInstanceStrong();
byte[] bytes = new byte[32];
random.nextBytes(bytes);
🛡️

Strongest available

Automatically selects the best algorithm for the platform.

📖

Explicit intent

Clearly communicates that strong randomness is required.

🔧

Configurable

Administrators can change the strong algorithm via security properties.

Old Approach
new SecureRandom()
Modern Approach
getInstanceStrong()
Since JDK
9
Difficulty
beginner
Strong random generation
Available

Widely available since JDK 9 (Sept 2017)

How it works

getInstanceStrong() returns the SecureRandom implementation configured as the strongest on the platform. This is controlled by the securerandom.strongAlgorithms security property.

Share 𝕏 🦋 in