org.random.rjgodoy.trng
Class MH_SecureRandomSpi

java.lang.Object
  extended by java.security.SecureRandomSpi
      extended by org.random.rjgodoy.trng.MH_SecureRandomSpi
All Implemented Interfaces:
Serializable

public class MH_SecureRandomSpi
extends SecureRandomSpi

SecureRandomSpi implementation that uses the True Random Number generator from www.random.org. Before the first instance of this class is constructed, several global System properties must be defined for configuring the shared the HTTP connection (which cannot be modified later). Other properties are related to the TRNG behaviour, then they are instance-specific and may be specified before constructing each instance. See MH_SecureRandom.

Author:
Javier Godoy
See Also:
Serialized Form

Constructor Summary
MH_SecureRandomSpi()
          Initializes an instance of MH_SecureRandomSpi.
 
Method Summary
protected  byte[] engineGenerateSeed(int numBytes)
          Returns the given number of seed bytes.
protected  void engineNextBytes(byte[] bytes)
          Generates a user-specified number of random bytes.
protected  void engineSetSeed(byte[] seed)
          Reseeds this random object.
protected  void finalize()
          Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MH_SecureRandomSpi

public MH_SecureRandomSpi()
                   throws NoSuchAlgorithmException,
                          NoSuchProviderException
Initializes an instance of MH_SecureRandomSpi.

The execution of this constructor is synchronized with the MH_SecureRandom class object for reading system properties

Throws:
NoSuchAlgorithmException - if org.random.rjgodoy.trng.prng_algorithm was specified, but no provider implements such algorithm.
NoSuchProviderException - if org.random.rjgodoy.trng.prng_provider wsas specified, but it is not installed
IllegalArgumentException - if any of org.random.rjgodoy.trng.mode, org.random.rjgodoy.trng.fallback is specified and it is invalid
Method Detail

engineGenerateSeed

protected byte[] engineGenerateSeed(int numBytes)
Returns the given number of seed bytes. This call may be used to seed other random number generators.

This method invoked engineNextBytes(byte[]) and pass it a byte array of length numBytes.

Specified by:
engineGenerateSeed in class SecureRandomSpi
Parameters:
numBytes - the number of seed bytes to generate.
Returns:
the seed bytes.
Throws:
ProviderException - see engineNextBytes(byte[])

engineSetSeed

protected void engineSetSeed(byte[] seed)
Reseeds this random object. The given seed supplements, rather than replaces, the existing seed. Thus, repeated calls are guaranteed never to reduce randomness.

If a PRNG is being used, this method invokes the PNRG's SecureRandom.setSeed(byte[]) method with the given argument. If no PRNG is being used, this method does nothing.

Specified by:
engineSetSeed in class SecureRandomSpi
Parameters:
seed - the seed.

engineNextBytes

protected void engineNextBytes(byte[] bytes)
Generates a user-specified number of random bytes.

If a call to engineSetSeed(byte[]) had not occurred previously, the first call to this method forces this SecureRandom implementation to seed itself. This self-seeding will not occur if engineSetSeed was previously called.

Specified by:
engineNextBytes in class SecureRandomSpi
Parameters:
bytes - the array to be filled in with random bytes.
Throws:
ProviderException - if fallback is TRNG, there are no available bytes, and the thread is interrupted while waiting for the quota top-up.

finalize

protected void finalize()
                 throws Throwable
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

Closes the shared socket upon finalization.

Overrides:
finalize in class Object
Throws:
Throwable


Submit a bug or request a featureCopyright © (2008-2011) Roberto Javier Godoy
Project Web Hosted by SourceForge.netSouceForge.net is registered trademark of SourceForge, Inc., in the United States and other countries.