public class AutoReseedRandom extends SecureRandom implements Runnable
SecureRandom which is able to reseed itself every reseedingPeriod milliseconds. All methods
inherited from SecureRandom are passed to delegate. When reseeding the delegate is recreated. The
reseeding happens in a new Thread not to block the Thread in which any of the next* methods is
called.| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_RANDOM_ALGORITHM
Default random algorithm "SHA1PRNG".
|
static String |
DEFAULT_RANDOM_ALGORITHM_PROVIDER
Default random algorithm provider.
|
static long |
DEFAULT_RESEEDING_PERIOD
Default expiration time in milliseconds, an equivalent of 24 hours.
|
static int |
DEFAULT_SEED_LENGTH
Default seed length 32.
|
| Constructor and Description |
|---|
AutoReseedRandom() |
AutoReseedRandom(String algorithm,
String algorithmProvider,
int seedLength,
long reseedingPeriod) |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
generateSeed(int numBytes) |
String |
getAlgorithm() |
boolean |
nextBoolean() |
void |
nextBytes(byte[] bytes) |
double |
nextDouble() |
float |
nextFloat() |
double |
nextGaussian() |
int |
nextInt() |
int |
nextInt(int n) |
long |
nextLong() |
void |
run()
Called from the reseeding
Thread. |
void |
setSeed(byte[] seed) |
void |
setSeed(long seed) |
getInstance, getInstance, getInstance, getInstanceStrong, getProvider, getSeed, nextpublic static final long DEFAULT_RESEEDING_PERIOD
public static final String DEFAULT_RANDOM_ALGORITHM
public static final String DEFAULT_RANDOM_ALGORITHM_PROVIDER
public static final int DEFAULT_SEED_LENGTH
public AutoReseedRandom()
public AutoReseedRandom(String algorithm, String algorithmProvider, int seedLength, long reseedingPeriod)
algorithm - See SecureRandom.getInstance(String, String).algorithmProvider - See SecureRandom.getInstance(String, String). In most cases you will want to use
DEFAULT_RANDOM_ALGORITHM_PROVIDER which will lead to using
SecureRandom.getInstance(String) instead of SecureRandom.getInstance(String, String). You may want
to consider using "NativePRNG", "SUN" or other providers if you have special requirements.seedLength - number of Bytes, see SecureRandom.generateSeed(int).reseedingPeriod - Time in milliseconds after which the delegate gets reseeded by resetRandom()public void run()
Thread.run in interface RunnablecheckReseed(),
Runnable.run()public String getAlgorithm()
getAlgorithm in class SecureRandompublic void setSeed(byte[] seed)
setSeed in class SecureRandompublic void setSeed(long seed)
setSeed in class SecureRandompublic void nextBytes(byte[] bytes)
nextBytes in class SecureRandompublic byte[] generateSeed(int numBytes)
generateSeed in class SecureRandompublic boolean nextBoolean()
nextBoolean in class Randompublic double nextDouble()
nextDouble in class Randompublic double nextGaussian()
nextGaussian in class RandomCopyright © 2018 JBoss by Red Hat. All Rights Reserved.