Class au.net.aba.security.SecureRandom
All Packages Class Hierarchy This Package Previous Next Index
Class au.net.aba.security.SecureRandom
java.lang.Object
|
+----java.util.Random
|
+----au.net.aba.security.SecureRandom
- public final class SecureRandom
- extends Random
This class provides a cryptographically strong pseudo-random number
generator based on the SHA-1 hash algorithm.
The calls inherited from Random will be implemented in terms of the
strengthened functionality.
NOTE: For seed generator (ie the default constructor) we only use
a very small number of random bytes using an entropy generator of
unknown quality. For secure results further entropy should be
added to the generator.
-
ident
-
-
SecureRandom()
- This empty constructor automatically seeds the generator.
-
SecureRandom(byte[])
- This constructor uses a user-provided seed in preference to the
self-seeding algorithm referred to in the empty constructor
description.
-
getSeed(int)
- Generate random bytes.
-
next(int)
- Generates an integer containing the user-specified number of
pseudo-random bits (right justified, with leading zeros).
-
nextBytes(byte[])
- Generates a user-specified number of random bytes.
-
setSeed(byte[])
- Re-seeds this random object.
-
setSeed(long)
- Re-seeds this random object, using the eight bytes contained in
the given long seed.
ident
public final static String ident
SecureRandom
public SecureRandom()
- This empty constructor automatically seeds the generator. We
attempt to provide sufficient seed bytes to completely randomise
the internal state of the generator (20 bytes). Note, however,
that our seed generation algorithm has not been thoroughly
studied or widely deployed. It relies on counting the number of
times that the calling thread can yield while waiting for
another thread to sleep for a specified interval.
SecureRandom
public SecureRandom(byte seed[])
- This constructor uses a user-provided seed in preference to the
self-seeding algorithm referred to in the empty constructor
description. It may be preferable to the empty constructor if
the caller has access to high-quality random bytes from some
physical device (for example, a radiation detector or a noisy
diode).
- Parameters:
- seed - the seed for this generator
setSeed
public synchronized void setSeed(byte seed[])
- Re-seeds this random object. The given seed supplements, rather *
than replaces, the existing seed. Thus, repeated calls are
guaranteed never to reduce randomness.
- Parameters:
- seed - A series of bytes to seed with.
setSeed
public void setSeed(long l)
- Re-seeds this random object, using the eight bytes contained in
the given long seed. The given seed supplements, rather than
replaces, the existing seed. Thus, repeated calls are guaranteed
never to reduce randomness.
This method is defined for compatibility with java.util.Random.
- Parameters:
- l - the seed.
- Overrides:
- setSeed in class Random
nextBytes
public synchronized void nextBytes(byte bytes[])
- Generates a user-specified number of random bytes. This method
is used as the basis of all random entities returned by this
class (except seed bytes). Thus, it may be overridden to change
the behaviour of the class.
- Parameters:
- bytes - the array to be filled in with random bytes.
next
protected final int next(int numBits)
- Generates an integer containing the user-specified number of
pseudo-random bits (right justified, with leading zeros). This
method overrides a java.util.Random method, and serves to
provide a source of random bits to all of the methods inherited
from that class (for example, nextInt, nextLong, and
nextFloat).
- Parameters:
- numBits - - number of pseudo-random bits to be generated,
where 0 <= numBits <= 32.
- Overrides:
- next in class Random
getSeed
public static byte[] getSeed(int numBytes)
- Generate random bytes. This is a poor mans version of what
is available in the JDK 1.1 and should be chucked as soon as
possible. We allocate a minimum of 1 second for each loop, adding
some number between 0 and 127 milliseconds at each iteration.
Note: this will give us much greater protection than we get from
just using the date, don't rely on it as the only source of
randomness though.
All Packages Class Hierarchy This Package Previous Next Index