public abstract class HashObjectSeedGenerator extends VarLengthSeedGenerator
The usage is rather simple. You just have to subclass this class and implement
the abstract method extractSeedData()
. Every time the user passes
an object to this class via addSeedObject
this object will be
passed to extractSeedData()
. The task of this method is
to extract randomness from the object and call one of the updateHash()
methods. Note that it should never hurt to hash not only the random parts
but also deterministic data, i.e. you can hash all fields of the object.
It is recommended to hash the current time as obtained by
System.currentTimeMillis()
in addition to be object itself.
For more information see the documentation of the extractSeedData()
and getMessageDigest()
methods.
SeedGenerator
,
AWT11SeedGenerator
,
AWT10SeedGenerator
seedGenListener
Modifier | Constructor and Description |
---|---|
protected |
HashObjectSeedGenerator(int numBits)
Constructor for use by subclasses.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addSeedObject(java.lang.Object obj)
Feed a new seed object to this seed generator.
|
protected abstract int |
extractSeedData(java.lang.Object obj)
This method extracts the random information from the object and updates
the hash accordingly.
|
protected java.security.MessageDigest |
getMessageDigest()
Return a new MessageDigest object to be used to digest the random
information.
|
byte[] |
getSeed()
Return the random seed.
|
int[] |
getStatus()
Return the current status of seed generation.
|
void |
reinit(int numBits)
Sets the number of bits to generate.
|
protected void |
updateHash(byte[] data)
Update the hash by data.
|
protected void |
updateHash(long l)
Update the hash by longToBytes(l).
|
protected void |
updateHash(java.lang.String data)
Update the hash by data.getBytes().
|
getDefault, getSeedLength, hasSeedLengthChanged, setDefault, setSeedLength
callSeedGenListener, getDefault, getDefaultSeedGenerator, seedAvailable, setDefaultSeedGenerator, setSeedGenListener
protected HashObjectSeedGenerator(int numBits)
public void reinit(int numBits)
VarLengthSeedGenerator
getSeed()
gets called.reinit
in class VarLengthSeedGenerator
numBits
- the number of bits to generateprotected java.security.MessageDigest getMessageDigest()
public final int[] getStatus()
getStatus
in class SeedGenerator
protected final void updateHash(byte[] data)
protected final void updateHash(java.lang.String data)
protected final void updateHash(long l)
protected abstract int extractSeedData(java.lang.Object obj) throws RandomException
addSeedObject()
only. It should return the number of random
bits obtained from the object. If the object is an instance of an unsupported
class it should throw a RandomException
.RandomException
public final boolean addSeedObject(java.lang.Object obj) throws RandomException
extractSeedData()
and the SeedGenListener (if one is registered).
If more seed objects are needed it return true, otherwise false.
If seed generation is already completed when this method is called,
it will instantly return false.RandomException
public final byte[] getSeed()
getSeed
in class SeedGenerator