|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.Random
java.security.SecureRandom
public class SecureRandom
An interface to a cryptographically secure pseudo-random number generator (PRNG). Random (or at least unguessable) numbers are used in all areas of security and cryptography, from the generation of keys and initialization vectors to the generation of random padding bytes.
Constructor Summary | |
---|---|
|
SecureRandom()
Default constructor for SecureRandom. |
|
SecureRandom(byte[] seed)
A constructor for SecureRandom. |
protected |
SecureRandom(SecureRandomSpi secureRandomSpi,
Provider provider)
A constructor for SecureRandom. |
Method Summary | |
---|---|
byte[] |
generateSeed(int numBytes)
Returns the specified number of seed bytes. |
String |
getAlgorithm()
Returns the algorithm name used or "unknown" when the algorithm used couldn't be determined (as when constructed by the protected 2 argument constructor). |
static SecureRandom |
getInstance(String algorithm)
Returns an instance of a SecureRandom from the first provider
that implements it. |
static SecureRandom |
getInstance(String algorithm,
Provider provider)
Returns an instance of a SecureRandom for the specified
algorithm from the given provider. |
static SecureRandom |
getInstance(String algorithm,
String provider)
Returns an instance of a SecureRandom for the specified
algorithm from the named provider. |
Provider |
getProvider()
Returns the provider being used by the current SecureRandom class. |
static byte[] |
getSeed(int numBytes)
Returns the given number of seed bytes. |
protected int |
next(int numBits)
Generates an integer containing the user specified number of random bits. |
void |
nextBytes(byte[] bytes)
Generates a user specified number of bytes. |
void |
setSeed(byte[] seed)
Seeds the SecureRandom. |
void |
setSeed(long seed)
Seeds the SecureRandom. |
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 |
---|
public SecureRandom()
getInstance(java.lang.String)
.
public SecureRandom(byte[] seed)
seed
- Seed bytes for classprotected SecureRandom(SecureRandomSpi secureRandomSpi, Provider provider)
secureRandomSpi
- A SecureRandomSpi classprovider
- A Provider classMethod Detail |
---|
public static SecureRandom getInstance(String algorithm) throws NoSuchAlgorithmException
SecureRandom
from the first provider
that implements it.
algorithm
- The algorithm name.
SecureRandom
implementing the given algorithm.
NoSuchAlgorithmException
- If no installed provider implements the
given algorithm.
IllegalArgumentException
- if algorithm
is
null
or is an empty string.public static SecureRandom getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
SecureRandom
for the specified
algorithm from the named provider.
algorithm
- The algorithm name.provider
- The provider name.
SecureRandom
implementing the chosen
algorithm.
NoSuchAlgorithmException
- If the named provider does not implement
the algorithm, or if the implementation cannot be instantiated.
NoSuchProviderException
- If no provider named provider
is currently installed.
IllegalArgumentException
- if either algorithm
or
provider
is null
or empty.public static SecureRandom getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
SecureRandom
for the specified
algorithm from the given provider.
algorithm
- The SecureRandom
algorithm to create.provider
- The provider to use.
NoSuchAlgorithmException
- If the algorithm cannot be found, or if
the class cannot be instantiated.
IllegalArgumentException
- if either algorithm
or
provider
is null
, or if
algorithm
is an empty string.public final Provider getProvider()
public String getAlgorithm()
public void setSeed(byte[] seed)
seed
- seed bytes to seed withpublic void setSeed(long seed)
setSeed
in class Random
seed
- 8 seed bytes to seed withpublic void nextBytes(byte[] bytes)
nextBytes
in class Random
bytes
- array to store generated bytes inprotected final int next(int numBits)
next
in class Random
numBits
- number of random bits to get, 0 <= numBits <= 32;
public static byte[] getSeed(int numBytes)
numBytes
- number of seed bytes to get
public byte[] generateSeed(int numBytes)
numBytes
- number of seed bytes to get
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |