com.mindbright.util
Class SecureRandomAndPad

java.lang.Object
  extended byjava.util.Random
      extended bycom.mindbright.jca.security.SecureRandom
          extended bycom.mindbright.util.SecureRandomAndPad
All Implemented Interfaces:
java.io.Serializable

public class SecureRandomAndPad
extends SecureRandom

Class for generating both random bytes and pad bytes. The pad bytes are also pseudo-random but generated by a different algorithm (arcfour) and uses a different seed.

See Also:
Serialized Form

Constructor Summary
SecureRandomAndPad()
          Simple constructor.
SecureRandomAndPad(SecureRandom random)
          Creates an instance which uses the given random number generator.
 
Method Summary
 byte[] generateSeed(int numBytes)
          Generate random seed bytes.
 void nextBytes(byte[] bytes)
          Fills the given array with random bytes.
 void nextPadBytes(byte[] bytes, int off, int len)
          Get a number of pad bytes.
 void setPadSeed(byte[] seed)
          Seed the pad generator.
 void setSeed(byte[] seed)
          Seeds the random number generator.
 
Methods inherited from class com.mindbright.jca.security.SecureRandom
getInstance, getInstance, getProvider, getSeed, next, setSeed
 
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

SecureRandomAndPad

public SecureRandomAndPad()
Simple constructor.


SecureRandomAndPad

public SecureRandomAndPad(SecureRandom random)
Creates an instance which uses the given random number generator.

Parameters:
random - underlying random number generator
Method Detail

setPadSeed

public void setPadSeed(byte[] seed)
Seed the pad generator. This should be called once before extracting pad bytes. Otherwise the pad bytes will be nonrandom.

Parameters:
seed - array of random data which is used to seed the generator

nextPadBytes

public void nextPadBytes(byte[] bytes,
                         int off,
                         int len)
Get a number of pad bytes.

Parameters:
bytes - array into which the bytes should be stored
off - offset to first byte to store in array
len - number of pad bytes to store

generateSeed

public byte[] generateSeed(int numBytes)
Generate random seed bytes. These bytes are generated by the normal random number generator.

Overrides:
generateSeed in class SecureRandom
Parameters:
numBytes - how many bytes to generate
Returns:
an array of random bytes

nextBytes

public void nextBytes(byte[] bytes)
Fills the given array with random bytes.

Overrides:
nextBytes in class SecureRandom
Parameters:
bytes - array to fill with random bytes

setSeed

public void setSeed(byte[] seed)
Seeds the random number generator.

Overrides:
setSeed in class SecureRandom
Parameters:
seed - array of random data which is used to seed the generator