/// <summary> /// Returns the SecureRandom used to generate secure random data. /// <para> /// Creates and initializes if null. Uses /// <c>System.currentTimeMillis() + System.identityHashCode(this)</c> as the default seed. /// </para> /// </summary> /// <returns>the SecureRandom used to generate secure random data, wrapped in a /// <see cref="RandomGenerator"/>.</returns> private RandomGenerator getSecRan() { if (secRand == null) { secRand = RandomGeneratorFactory.createRandomGenerator(new SecureRandom()); //Find unix timestamp (seconds since 01/01/1970) long ticks = DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks; ticks /= 10000; //current timestamp in millis secRand.setSeed(ticks + this.GetHashCode()); } return(secRand); }
/// <summary> /// Sets the PRNG algorithm for the underlying SecureRandom instance using /// the Security Provider API. The Security Provider API is defined in <a /// href = /// "http://java.sun.com/j2se/1.3/docs/guide/security/CryptoSpec.html#AppA"> /// Java Cryptography Architecture API Specification & Reference.</a> /// <para> /// <strong>USAGE NOTE:</strong> This method carries <i>significant</i> /// overhead and may take several seconds to execute. /// </para> /// </summary> /// <param name="algorithm">the name of the PRNG algorithm</param> public void setSecureAlgorithm(String algorithm) { secRand = RandomGeneratorFactory.createRandomGenerator(SecureRandom.GetInstance(algorithm)); }