Strong random generation
Get the platform's strongest SecureRandom implementation.
Porównanie kodu
✕ 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);
Widzisz problem z tym kodem? Daj nam znać.
Dlaczego nowoczesne podejście wygrywa
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.
Stare podejście
new SecureRandom()
Nowoczesne podejście
getInstanceStrong()
Od JDK
9
Poziom trudności
Początkujący
Wsparcie JDK
Strong random generation
Dostępne
Widely available since JDK 9 (Sept 2017)
Jak to działa
getInstanceStrong() returns the SecureRandom implementation configured as the strongest on the platform. This is controlled by the securerandom.strongAlgorithms security property.
Powiązana dokumentacja