ewe.security
Class SecureRandom

java.lang.Object
  extended byewe.util.Random
      extended byewe.security.SecureRandom

public class SecureRandom
extends Random


Constructor Summary
SecureRandom()
           
SecureRandom(byte[] seed)
           
 
Method Summary
 byte[] generateSeed(int numBytes)
           
protected  int next(int numBits)
          Generates an integer containing the user specified number of random bits.
 void nextBytes(byte[] bytes)
          Fills an array of bytes with random numbers.
 void setSeed(byte[] seed)
           
 void setSeed(long seed)
          Seeds the SecureRandom.
 
Methods inherited from class ewe.util.Random
nextBoolean, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Constructor Detail

SecureRandom

public SecureRandom()

SecureRandom

public SecureRandom(byte[] seed)
Method Detail

setSeed

public void setSeed(byte[] seed)

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.

Overrides:
setSeed in class Random
Parameters:
seed - 8 seed bytes to seed with

nextBytes

public void nextBytes(byte[] bytes)
Description copied from class: Random
Fills an array of bytes with random numbers. All possible values are (approximately) equally likely. The JDK documentation gives no implementation, but it seems to be:
public void nextBytes(byte[] bytes)
{
  for (int i = 0; i < bytes.length; i += 4)
  {
    int random = next(32);
    for (int j = 0; i + j < bytes.length && j < 4; j++)
    {
      bytes[i+j] = (byte) (random & 0xff)
      random >>= 8;
    }
  }
}

Overrides:
nextBytes in class Random
Parameters:
bytes - the byte array that should be filled

generateSeed

public byte[] generateSeed(int numBytes)

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.

Overrides:
next in class Random
Parameters:
numBits - number of random bits to get, 0 <= numBits <= 32;
Returns:
the random bits