Build 1.0_r1(from source)

java.security
Class SecureRandom

java.lang.Object
  extended by java.util.Random
      extended by java.security.SecureRandom
All Implemented Interfaces:
Serializable

public class SecureRandom
extends Random

See Also:
Serialized Form

Constructor Summary
  SecureRandom()
          Constructs a new instance of this class.
  SecureRandom(byte[] seed)
          Constructs a new instance of this class.
protected SecureRandom(SecureRandomSpi secureRandomSpi, Provider provider)
           
 
Method Summary
 byte[] generateSeed(int numBytes)
          Generates a certain number of seed bytes
 String getAlgorithm()
           
static SecureRandom getInstance(String algorithm)
           
static SecureRandom getInstance(String algorithm, Provider provider)
           
static SecureRandom getInstance(String algorithm, String provider)
          Returns a new SecureRandom which is capable of running the algorithm described by the argument.
 Provider getProvider()
          Returns the Provider of the secure random represented by the receiver.
static byte[] getSeed(int numBytes)
          Returns the given number of seed bytes, computed using the seed generation algorithm used by this class.
protected  int next(int numBits)
          Returns a pseudo-random uniformly distributed int value of the number of bits specified by the argument bits as described by Donald E.
 void nextBytes(byte[] bytes)
          Modifies the byte array by a random sequence of bytes generated by this random number generator.
 void setSeed(byte[] seed)
           
 void setSeed(long seed)
          Reseeds this random object with the eight bytes described by the representation of the long provided.
 
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

SecureRandom

public SecureRandom()
Constructs a new instance of this class. Users are encouraged to use getInstance() instead. An implementation for the highest-priority provider is returned. The instance returned will not have been seeded.


SecureRandom

public SecureRandom(byte[] seed)
Constructs a new instance of this class. Users are encouraged to use getInstance() instead. An implementation for the highest-priority provider is returned. The instance returned will be seeded with the parameter.

Parameters:
seed - bytes forming the seed for this generator.

SecureRandom

protected SecureRandom(SecureRandomSpi secureRandomSpi,
                       Provider provider)
Method Detail

getInstance

public static SecureRandom getInstance(String algorithm)
                                throws NoSuchAlgorithmException
Throws:
NoSuchAlgorithmException

getInstance

public static SecureRandom getInstance(String algorithm,
                                       String provider)
                                throws NoSuchAlgorithmException,
                                       NoSuchProviderException
Returns a new SecureRandom which is capable of running the algorithm described by the argument. The result will be an instance of a subclass of SecureRandomSpi which implements that algorithm.

Parameters:
algorithm - java.lang.String Name of the algorithm desired
provider - java.security.Provider Provider which has to implement the algorithm
Returns:
SecureRandom a concrete implementation for the algorithm desired.
Throws:
NoSuchAlgorithmException - If the algorithm cannot be found
NoSuchProviderException

getInstance

public static SecureRandom getInstance(String algorithm,
                                       Provider provider)
                                throws NoSuchAlgorithmException
Throws:
NoSuchAlgorithmException

getProvider

public final Provider getProvider()
Returns the Provider of the secure random represented by the receiver.

Returns:
Provider an instance of a subclass of java.security.Provider

getAlgorithm

public String getAlgorithm()

setSeed

public void setSeed(byte[] seed)

setSeed

public void setSeed(long seed)
Reseeds this random object with the eight bytes described by the representation of the long provided.

Overrides:
setSeed in class Random
Parameters:
seed - long Number whose representation to use to reseed the receiver.
See Also:
Random.next(int), Random.Random(), Random.Random(long)

nextBytes

public void nextBytes(byte[] bytes)
Description copied from class: Random
Modifies the byte array by a random sequence of bytes generated by this random number generator.

Overrides:
nextBytes in class Random
Parameters:
bytes - non-null array to contain the new random bytes
See Also:
Random.next(int)

next

protected final int next(int numBits)
Description copied from class: Random
Returns a pseudo-random uniformly distributed int value of the number of bits specified by the argument bits as described by Donald E. Knuth in The Art of Computer Programming, Volume 2: Seminumerical Algorithms, section 3.2.1.

Overrides:
next in class Random
Parameters:
numBits - number of bits of the returned value
Returns:
int a pseudo-random generated int number
See Also:
Random.nextBytes(byte[]), Random.nextDouble(), Random.nextFloat(), Random.nextInt(), Random.nextInt(int), Random.nextGaussian(), Random.nextLong()

getSeed

public static byte[] getSeed(int numBytes)
Returns the given number of seed bytes, computed using the seed generation algorithm used by this class.

Parameters:
numBytes - int the given number of seed bytes
Returns:
byte[] The seed bytes generated

generateSeed

public byte[] generateSeed(int numBytes)
Generates a certain number of seed bytes

Parameters:
numBytes - int Number of seed bytes to generate
Returns:
byte[] The seed bytes generated

Build 1.0_r1(from source)

Please submit a feedback, bug or feature