This commit is contained in:
Sebastian Stenzel
2016-03-25 16:41:30 +01:00
parent 553cb5ee3d
commit a385f2eaef

View File

@@ -27,7 +27,12 @@ public class CryptoEngineModule {
@Provides
public SecureRandom provideSecureRandom() {
try {
return SecureRandom.getInstanceStrong();
// https://tersesystems.com/2015/12/17/the-right-way-to-use-securerandom/
final SecureRandom nativeRandom = SecureRandom.getInstanceStrong();
byte[] seed = nativeRandom.generateSeed(55); // NIST SP800-90A suggests 440 bits for SHA1 seed
SecureRandom sha1Random = SecureRandom.getInstance("SHA1PRNG");
sha1Random.setSeed(seed);
return sha1Random;
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException("No strong PRNGs available.", e);
}