![JAR search and dependency download from the Maven repository](/logo.png)
org.spongycastle.crypto.prng.X931SecureRandom Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle
intended for the Android platform. Android unfortunately ships with a stripped-down version of
Bouncy Castle, which prevents easy upgrades - Spongy Castle overcomes this and provides a full,
up-to-date version of the Bouncy Castle cryptographic libs.
The newest version!
package org.spongycastle.crypto.prng;
import java.security.SecureRandom;
public class X931SecureRandom
extends SecureRandom
{
private final boolean predictionResistant;
private final SecureRandom randomSource;
private final X931RNG drbg;
X931SecureRandom(SecureRandom randomSource, X931RNG drbg, boolean predictionResistant)
{
this.randomSource = randomSource;
this.drbg = drbg;
this.predictionResistant = predictionResistant;
}
public void setSeed(byte[] seed)
{
synchronized (this)
{
if (randomSource != null)
{
this.randomSource.setSeed(seed);
}
}
}
public void setSeed(long seed)
{
synchronized (this)
{
// this will happen when SecureRandom() is created
if (randomSource != null)
{
this.randomSource.setSeed(seed);
}
}
}
public void nextBytes(byte[] bytes)
{
synchronized (this)
{
// check if a reseed is required...
if (drbg.generate(bytes, predictionResistant) < 0)
{
drbg.reseed();
drbg.generate(bytes, predictionResistant);
}
}
}
public byte[] generateSeed(int numBytes)
{
return EntropyUtil.generateSeed(drbg.getEntropySource(), numBytes);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy