|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Random | +--com.motorola.iden.security.SecureRandom
This class provides a cryptographically strong pseudo-random number generator (PRNG).
Like other algorithm-based classes in Java Security, SecureRandom provides implementation-independent algorithms, whereby a caller (application code) requests a particular PRNG algorithm and is handed back a SecureRandom object for that algorithm.
SecureRandom random = SecureRandom.getInstance("FIPS186");
The SecureRandom implementation attempts to completely
randomize the internal state of the generator itself unless
the caller follows the call to a getInstance
method
with a call to the setSeed
method:
SecureRandom random = SecureRandom.getInstance("FIPS186"); random.setSeed(seed);
After the caller obtains the SecureRandom object from the
getInstance
call, it can call nextBytes
to generate random bytes:
byte bytes[] = new byte[20]; random.nextBytes(bytes);
The caller may also invoke the generateSeed
method
to generate a given number of seed bytes (to seed other random number
generators, for example):
byte seed[] = random.generateSeed(20);MOTOROLA and the Stylized M Logo are registered trademarks of Motorola, Inc. Reg. U.S. Pat. & Tm. Off.
Constructor Summary | |
SecureRandom(byte[] seed)
This constructor is provided for backwards compatibility. |
Method Summary | |
byte[] |
generateSeed(int numBytes)
Returns the given number of seed bytes, computed using the seed generation algorithm that this class uses to seed itself. |
static SecureRandom |
getInstance(java.lang.String algorithm)
Creates a SecureRandom object. |
static SecureRandom |
getInstance(java.lang.String algorithm,
java.lang.String Package)
Creates a SecureRandom object. |
void |
nextBytes(byte[] bytes)
Generates a user-specified number of random bytes. |
void |
setSeed(byte[] seed)
Reseeds this random object. |
Methods inherited from class java.util.Random |
next, nextBoolean, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, setSeed |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public SecureRandom(byte[] seed)
This constructor is provided for backwards compatibility.
The caller is encouraged to use one of the alternative
getInstance
methods to obtain a SecureRandom object, and
then to call the setSeed
method to seed it.
seed
- the seed.Method Detail |
public static SecureRandom getInstance(java.lang.String algorithm) throws NoSuchAlgorithmException
NoSuchAlgorithmException
- if the PRNG algorithm is
not available in the caller's environment.public static SecureRandom getInstance(java.lang.String algorithm, java.lang.String Package) throws NoSuchAlgorithmException
algorithm
- the name of RNG algorithmPackage
- the Package which the end user provied RNG belongs to.NoSuchAlgorithmException
- if the PRNG algorithm is
not available in the caller's environment.public void setSeed(byte[] seed)
seed
is null
,
system generated seed would be used.seed
- the seed.public void nextBytes(byte[] bytes)
bytes
equals to
null
, no random bytes would be generated.nextBytes
in class java.util.Random
bytes
- the array to be filled in with random bytes.public byte[] generateSeed(int numBytes)
numBytes
equals to or less than zero
,
null
is returned.numBytes
- the number of seed bytes to generate.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |