Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.security

Class SecureRandom

java.lang.Object
|
+--java.util.Random
   |
   +--java.security.SecureRandom


public class SecureRandom

extends Random

SecureRandom is the class interface for using SecureRandom providers. It provides an interface to the SecureRandomSpi engine so that programmers can generate pseudo-random numbers.

Author:

Constructor Summary

SecureRandom()

Default constructor for SecureRandom.
SecureRandom(byte[] seed)

A constructor for SecureRandom.
SecureRandom(java.security.SecureRandomSpi secureRandomSpi, java.security.Provider provider)

A constructor for SecureRandom.

Method Summary

byte[]generateSeed(int numBytes)

Returns the specified number of seed bytes.
static java.security.SecureRandomgetInstance(java.lang.String algorithm)

Returns an instance of a SecureRandom.
static java.security.SecureRandomgetInstance(java.lang.String algorithm, java.lang.String provider)

Returns an instance of a SecureRandom.
static java.security.SecureRandomgetInstance(java.lang.String algorithm, java.security.Provider provider)

Returns an instance of a SecureRandom.
java.security.ProvidergetProvider()

Returns the provider being used by the current SecureRandom class.
static byte[]getSeed(int numBytes)

Returns the given number of seed bytes.
intnext(int numBits)

Generates an integer containing the user specified number of random bits.
voidnextBytes(byte[] bytes)

Generates a user specified number of bytes.
voidsetSeed(byte[] seed)

Seeds the SecureRandom.
voidsetSeed(long seed)

Seeds the SecureRandom.

Constructor Details

SecureRandom

public SecureRandom()

Default constructor for SecureRandom. It constructs a new SecureRandom by instantating the first SecureRandom algorithm in the default security provier. It is not seeded and should be seeded using setSeed or else on the first call to getnextBytes it will force a seed. It is maintained for backwards compatibility and programs should use getInstance.


SecureRandom

public SecureRandom(byte[] seed)

A constructor for SecureRandom. It constructs a new SecureRandom by instantating the first SecureRandom algorithm in the default security provier. It is seeded with the passed function and is useful if the user has access to hardware random device (like a radiation detector). It is maintained for backwards compatibility and programs should use getInstance.

Parameters:


SecureRandom

protected SecureRandom(java.security.SecureRandomSpi secureRandomSpi, java.security.Provider provider)

A constructor for SecureRandom. It constructs a new SecureRandom using the specified SecureRandomSpi from the specified security provier.

Parameters:


Method Details

generateSeed

public byte[] generateSeed(int numBytes)

Returns the specified number of seed bytes.

Parameters:

Returns:


getInstance

public static SecureRandom getInstance(java.lang.String algorithm)

Returns an instance of a SecureRandom. It creates the class for the specified algorithm if it exists from a provider.

Parameters:

Returns:

Throws:


getInstance

public static SecureRandom getInstance(java.lang.String algorithm, java.lang.String provider)

Returns an instance of a SecureRandom. It creates the class for the specified algorithm from the specified provider.

Parameters:

Returns:

Throws:


getInstance

public static SecureRandom getInstance(java.lang.String algorithm, java.security.Provider provider)

Returns an instance of a SecureRandom. It creates the class for the specified algorithm from the given provider.

Parameters:

Throws:


getProvider

public final Provider getProvider()

Returns the provider being used by the current SecureRandom class.

Returns:


getSeed

public static byte[] getSeed(int numBytes)

Returns the given number of seed bytes. This method is maintained only for backwards capability.

Parameters:

Returns:


next

protected final int next(int numBits)

Generates an integer containing the user specified number of random bits. It is right justified and padded with zeros.

Parameters:

Returns:


nextBytes

public void nextBytes(byte[] bytes)

Generates a user specified number of bytes. This function is the basis for all the random functions.

Parameters:


setSeed

public void setSeed(byte[] seed)

Seeds the SecureRandom. The class is re-seeded for each call and each seed builds on the previous seed so as not to weaken security.

Parameters:


setSeed

public void setSeed(long seed)

Seeds the SecureRandom. The class is re-seeded for each call and each seed builds on the previous seed so as not to weaken security.

Parameters: