Class MH_SecureRandomSpi

  extended by
      extended by org.random.rjgodoy.trng.MH_SecureRandomSpi
All Implemented Interfaces:

public class MH_SecureRandomSpi
extends SecureRandomSpi

SecureRandomSpi implementation that uses the True Random Number generator from 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.

Javier Godoy
See Also:
Serialized Form

Constructor Summary
          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


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

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

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


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
numBytes - the number of seed bytes to generate.
the seed bytes.
ProviderException - see engineNextBytes(byte[])


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
seed - the seed.


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
bytes - the array to be filled in with random bytes.
ProviderException - if fallback is TRNG, there are no available bytes, and the thread is interrupted while waiting for the quota top-up.


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.

finalize in class Object

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