Class AutoReseedRandom
java.lang.Object
java.util.Random
java.security.SecureRandom
org.exoplatform.web.security.security.AutoReseedRandom
- All Implemented Interfaces:
Serializable,Runnable,RandomGenerator
Subclass of
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.- Author:
- Peter Palaga
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.random.RandomGenerator
RandomGenerator.ArbitrarilyJumpableGenerator, RandomGenerator.JumpableGenerator, RandomGenerator.LeapableGenerator, RandomGenerator.SplittableGenerator, RandomGenerator.StreamableGenerator -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAutoReseedRandom(String algorithm, String algorithmProvider, int seedLength, long reseedingPeriod) -
Method Summary
Methods inherited from class java.security.SecureRandom
getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstanceStrong, getParameters, getProvider, getSeed, next, nextBytes, reseed, reseed, toStringMethods inherited from class java.util.Random
doubles, doubles, doubles, doubles, from, ints, ints, ints, ints, longs, longs, longs, longsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.random.RandomGenerator
isDeprecated, nextDouble, nextDouble, nextExponential, nextFloat, nextFloat, nextGaussian, nextInt, nextLong, nextLong
-
Field Details
-
DEFAULT_RESEEDING_PERIOD
public static final long DEFAULT_RESEEDING_PERIODDefault expiration time in milliseconds, an equivalent of 24 hours.- See Also:
-
DEFAULT_RANDOM_ALGORITHM
Default random algorithm "SHA1PRNG".- See Also:
-
DEFAULT_RANDOM_ALGORITHM_PROVIDER
Default random algorithm provider. -
DEFAULT_SEED_LENGTH
public static final int DEFAULT_SEED_LENGTHDefault seed length 32.- See Also:
-
-
Constructor Details
-
AutoReseedRandom
public AutoReseedRandom() -
AutoReseedRandom
public AutoReseedRandom(String algorithm, String algorithmProvider, int seedLength, long reseedingPeriod) - Parameters:
algorithm- SeeSecureRandom.getInstance(String, String).algorithmProvider- SeeSecureRandom.getInstance(String, String). In most cases you will want to useDEFAULT_RANDOM_ALGORITHM_PROVIDERwhich will lead to usingSecureRandom.getInstance(String)instead ofSecureRandom.getInstance(String, String). You may want to consider using"NativePRNG","SUN"or other providers if you have special requirements.seedLength- number of Bytes, seeSecureRandom.generateSeed(int).reseedingPeriod- Time in milliseconds after which thedelegategets reseeded byresetRandom()
-
-
Method Details
-
run
public void run()Called from the reseedingThread. -
getAlgorithm
- Overrides:
getAlgorithmin classSecureRandom
-
setSeed
public void setSeed(byte[] seed) - Overrides:
setSeedin classSecureRandom
-
setSeed
public void setSeed(long seed) - Overrides:
setSeedin classSecureRandom
-
nextBytes
public void nextBytes(byte[] bytes) - Specified by:
nextBytesin interfaceRandomGenerator- Overrides:
nextBytesin classSecureRandom
-
generateSeed
public byte[] generateSeed(int numBytes) - Overrides:
generateSeedin classSecureRandom
-
nextInt
public int nextInt()- Specified by:
nextIntin interfaceRandomGenerator- Overrides:
nextIntin classRandom
-
nextInt
public int nextInt(int n) - Specified by:
nextIntin interfaceRandomGenerator- Overrides:
nextIntin classRandom
-
nextLong
public long nextLong()- Specified by:
nextLongin interfaceRandomGenerator- Overrides:
nextLongin classRandom
-
nextBoolean
public boolean nextBoolean()- Specified by:
nextBooleanin interfaceRandomGenerator- Overrides:
nextBooleanin classRandom
-
nextFloat
public float nextFloat()- Specified by:
nextFloatin interfaceRandomGenerator- Overrides:
nextFloatin classRandom
-
nextDouble
public double nextDouble()- Specified by:
nextDoublein interfaceRandomGenerator- Overrides:
nextDoublein classRandom
-
nextGaussian
public double nextGaussian()- Specified by:
nextGaussianin interfaceRandomGenerator- Overrides:
nextGaussianin classRandom
-