public abstract class SecRandom
extends java.security.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.SHA256FIPS186Random
.
SecureRandom
,
MessageDigestRandom
,
SHA256FIPS186Random
,
SeedGenerator
,
Serialized FormModifier | Constructor and Description |
---|---|
protected |
SecRandom()
Default constructor for backwards compatibility.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getAlgorithm()
Gets the name of the algorithm.
|
static java.security.SecureRandom |
getDefault()
Return a new instance of the default random number generator.
|
static void |
setDefault(java.lang.Class clazz)
Deprecated.
use
setDefault(String) |
static void |
setDefault(java.lang.String prng)
Set the default random number generator.
|
void |
setSeed()
Set the seed to the next seed generated by the current default seed
generator.
|
generateSeed, getInstance, getInstance, getInstance, getProvider, getSeed, next, nextBytes, setSeed, setSeed
public static final java.security.SecureRandom getDefault()
nextBytes()
). Calling
getDefault()
is the recommended way of obtaining a PRNG.
The initial default PRNG is iaik.security.random.SHA256FIPS186Random
.public static final void setDefault(java.lang.Class clazz) throws RandomException
setDefault(String)
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.java.lang.IllegalArgumentException
- if there was an error with the SecureRandomRandomException
public static final void setDefault(java.lang.String prng) throws java.security.NoSuchAlgorithmException
getDefault()
.prng
- The identifier of the default random.java.lang.IllegalArgumentException
- if there was an error with the SecureRandomjava.security.NoSuchAlgorithmException
public final void setSeed()
setSeed(SeedGenerator.getDefault().getSeed());
.public java.lang.String getAlgorithm()
getAlgorithm
in class java.security.SecureRandom