iaik.security.random
Class MetaSeedGenerator
java.lang.Object
|
+--iaik.security.random.SeedGenerator
|
+--iaik.security.random.MetaSeedGenerator
- public class MetaSeedGenerator
- extends SeedGenerator
This seed generator generates new seeds given an initial seed.
Often an application will need a number of seed generators. There is
no need to seed each one separately from e.g. new user events,
it is secure to generate a random seed only once and deduct further
seeds from it using deterministic methods.
This is what this class is for, it internally uses the system's
default PRNG. The JDK SecureRandom uses a very similar
mechanism.
To use it, first set the initial seed via one of the static setSeed()
methods. Then create as many instances as you like using the
constructors. It is anticipated that this seed generator will often
be used as the default seed generator following an initialisation
from user input.
NOTE: For obvious reasons, the initial seed should be as least as
long as the longest seed that later is to be deducted from it.
Also, as this classes uses the system's default PRNG (usually SHA1Random),
so it can never generate true random seeds longer than the PRNG
digest (160 bits for SHA1Random).
- See Also:
SeedGenerator,
SHA1Random
|
Constructor Summary |
MetaSeedGenerator()
Initialize generation of a seed with the default amount of
randomness (160 bit). |
MetaSeedGenerator(int numBits)
Initialize generation of a seed with the specified amount of
randomness. |
|
Method Summary |
byte[] |
getSeed()
Get the seed. |
int[] |
getStatus()
Return the status of seed generation. |
static void |
setSeed(byte[] seed)
Set the initial seed to this byte array. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
MetaSeedGenerator
public MetaSeedGenerator()
- Initialize generation of a seed with the default amount of
randomness (160 bit). See the notes at the top of this class
about the value of this number.
MetaSeedGenerator
public MetaSeedGenerator(int numBits)
throws RandomException
- Initialize generation of a seed with the specified amount of
randomness. This methods throws a RandomException if no initial
seed has been set via
setSeed().
See the notes at the top of this class
about the value of this number.
setSeed
public static void setSeed(byte[] seed)
- Set the initial seed to this byte array. The array can be of any size.
Note that this seed itself will never be returned by this class.
getStatus
public int[] getStatus()
- Return the status of seed generation. This is always
{numBits, numBits}, i.e. it is always ok to call getSeed().
- Overrides:
- getStatus in class SeedGenerator
getSeed
public byte[] getSeed()
- Get the seed. This will instantly return a seed of constantly
20 bytes length.
- Overrides:
- getSeed in class SeedGenerator