Have a look at the following codesample written in C#:
private static byte[] GetRandomBytes(int size)
{
byte[] buff = new byte[size];
// Create an array of crypto-secure random numbers
using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
{
rng.GetBytes(buff);
}
// Gets a random byte from a non-crypto-secure RNG and xors each element with it
// Alternatively, xor each element with a new random number
int unsafeRand = (byte)_random.Next(0, 255);
for (int i = 0; i < size; i++)
buff[i] ^= unsafeRand;
return buff;
}
Is it safe to combine the .NET cryptographically secure random number generators with an imperfect random number generator, for example via XOR
?