APPENDIX A

Appendix A: CryptGenRandom Seed Value Generator
(C# Language Version)

public static int getSeedValue ()
{
//The getSeedValue() class method produces four, 32-bit integers using the Microsoft CryptGenRandom
//[advapi32.dll] function. The CryptGenRandom is a cryptographically secure pseudorandom number generator function
//that produces random bytes which are multiples of 8 bits.
//The CryptoAPI uses underlying system entropy to seed its internal crypto-graphic PNG.
//The entropy pool is hashed using one of the SHA algorithms so it applies approximately 128-160 bits
//of randomness (4-5 32-bit words)

// ------------------------------------------
// Declare and initialize var1ables.
IntPtr hProv = new IntPtr();

uint dwLength = 32;
Byte[] pbBuffer;
pbBuffer = new byte [dwLength];

// ------------------------------------------

uint[] seed;
seed = new uint[4];

// ------------------------------------------

try
{
bool res = Crypt32.CryptAcquireContext(out hProv, **, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);

if (res == true )
{
bool res2 = Crypt32.CryptGenRandom{hProv, dwLength, pbBuffer);
if (res2 == true)
{
Buffer.BlockCopy(pbBuffer, 0, seed, 0, 16);

gSeedl = seed[0];
gSeed2 = seed[1];
gSeed3 = seed[2];
gSeed4 = seed[3];
} else
{
throw new ArgumentException("Error: Unable to Instantiate Crypt32.CryptGenRandom.");
}

bool res3 = Crypt32.CryptReleaseContext(hProv, 0);

return 1;
} else
{
throw new ("Error: Unable to instantiate Crypt32.CryptAcquireContext.");
}

catch (Exception ex)
{
throw new ArgumentException("Error = " + ex.Message);
}
}