Is cryptographic generator allowed in C #?

There seems to be no way to manually sow the RNGCryptoServiceProvider in C #. Is there really nothing simple that I can do below to get duplicate randomBytes here for debugging?

  RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();
  byte[] randomBytes = new byte[20];
  rngCsp.GetBytes(randomBytes);
  MessageBox.Show(Convert.ToBase64String(randomBytes));

I know that I can manually enter 20 bytes, but this is a pain because I really need a lot more than 20. In addition, I know that I can use a random number generator without cryptography, but in the end, I need the best random generation.

By the way, I would suggest that some processors have a true random generation in which seeding is physically impossible, but I do not think that my processor has such an opportunity. I wonder if anyone knows what I could do with my processor to reset the RNGCryptoServiceProvider environment and the RNGCryptoServiceProvider trick to use the previous seed ... I suppose I could set my clock back and reset some "user log bits" where- then ... I know that this would be impractical, but I wonder if anyone has ever been successful in this (although Microsoft's goal is probably to prevent this).
+4
source share
2 answers

RNGCryptoServiceProvider. , System.Security.Cryptography.RandomNumberGenerator ( RNGCryptoServiceProvider):

class DeterministicRandomGenerator : System.Security.Cryptography.RandomNumberGenerator
{
    Random r = new Random(0);
    public override void GetBytes(byte[] data)
    {
        r.NextBytes(data);
    }
    public override void GetNonZeroBytes(byte[] data)
    {
        // simple implementation
        for (int i = 0; i < data.Length; i++)
            data[i] = (byte)r.Next(1, 256);
    }
}

, Random 0, . RNGCryptoServiceProvider :

    RandomNumberGenerator rngCsp = 
#if DEBUG
    new DeterministicRandomGenerator(); // get deterministic values if debugging
#else
    new RNGCryptoServiceProvider(); // otherwise, use CryptoRNG
#endif
    byte[] randomBytes = new byte[20];
    rngCsp.GetBytes(randomBytes);
    MessageBox.Show(Convert.ToBase64String(randomBytes));

, -, , reset RNGCryptoServiceProvider RNGCryptoServiceProvider

RNGCryptoServiceProvider Win32 CryptGenRandom, - ( ). . ( Win32 API ,.NET API . , , .) CryptGenRandom , :

, , , , , , , , , , , , , . (PRNG). Windows Vista 1 (SP1) PRNG AES, NIST Special Edition 800-90. Windows Vista, Windows Storage Server 2003 Windows XP PRNG, (FIPS) 186-2.

"" RNGCryptoServiceProvider, , .

+7

, , , , , .

Mersenne Twister , PRNG - , - RCPCryptoServiceProvider .

randomBytes . , , RCP CSP. , .

0

All Articles