|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Random | +--java.security.SecureRandom | +--iaik.security.random.SecRandom
The SecRandom class is the base class of all IAIK implemented secure pseudo random number generators (PRNGs). For compatibility with the JDK it is a subclass of java.security.SecureRandom, which in turn extends java.util.Random. Programmers who themselves want to implement a secure PRNG should subclass this class for compatibility and because this class takes care of some of the pecularities of the JDK SecureRandom.
Subclasses just need to implement the abstract
engineNextBytes()
and engineSetSeed()
methods and a no-args constructor. Subclasses should not seed themselves
in the constructor, they should wait for the application to call a
setSeed()
method explicitly with data from an appropriate
random source. This class makes sure that engineNextBytes()
is never called before a seed has been set, if necessary by calling
setSeed()
itself with data from the default SeedGenerator.
This class also serves as storage point for the system's default
secure PRNG. Applications which want to use a secure PRNG should typically call
SecRandom.getDefault()
instead of instantiating one particular
PRNG directly. This will allow the PRNG used throughout the application to
be set by a simple SecRandom.setDefault()
call. The initial
default PRNG is iaik.security.random.SHA1Random
.
SecureRandom
,
MessageDigestRandom
,
SHA1Random
,
SeedGenerator
, Serialized FormConstructor Summary | |
protected |
SecRandom()
Constructor for use by subclasses. |
Method Summary | |
protected abstract void |
engineNextBytes(byte[] bytes)
Return the next bytes.length random bytes. |
protected abstract void |
engineSetSeed(byte[] seed)
Set the seed to be used for random number generation. |
static SecureRandom |
getDefault()
Return a new instance of the default random number generator. |
void |
nextBytes(byte[] bytes)
Return the next bytes.length random bytes. |
static void |
setDefault(Class clazz)
Set the default random number generator. |
void |
setSeed()
Set the seed to the next seed generated by the current default seed generator. |
void |
setSeed(byte[] seed)
Set the seed to be used for random number generation. |
void |
setSeed(long seed)
Set the seed to the given long int. |
Methods inherited from class java.security.SecureRandom |
generateSeed, getInstance, getInstance, getProvider, getSeed, next |
Methods inherited from class java.util.Random |
nextBoolean, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected SecRandom()
Method Detail |
public static final SecureRandom getDefault()
nextBytes()
).
Calling getDefault()
is the recommended
way of obtaining a PRNG.public static final void setDefault(Class clazz) throws RandomException
getDefault()
.
The PRNG must have a no-args constructor accessible to this class.clazz
- The default random class. It must be
java.security.SecureRandom
or a subclass
of it.IllegalArgumentException
- if there was an error with the SecureRandompublic final void nextBytes(byte[] bytes)
setSeed()
will be called.
This methods calls engineNextBytes()
.nextBytes
in class SecureRandom
public final void setSeed(byte[] seed)
engineSetSeed()
.setSeed
in class SecureRandom
public final void setSeed(long seed)
setSeed(byte[])
. This method is included mainly
for compatibility, a 64 bit seed will generally be too short
for cryptographic applications and should not be used.setSeed
in class SecureRandom
public final void setSeed()
setSeed(SeedGenerator.getDefault().getSeed());
.protected abstract void engineNextBytes(byte[] bytes)
protected abstract void engineSetSeed(byte[] seed)
|
This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |