From 8accb371a1855b54d5da6d05e6d2e26fe86e739d Mon Sep 17 00:00:00 2001 From: Edward Ned Harvey Date: Tue, 5 Aug 2014 11:05:30 -0400 Subject: use CryptoApiRandomGenerator in addition to other entropy sources --- crypto/src/security/SecureRandom.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'crypto/src/security') diff --git a/crypto/src/security/SecureRandom.cs b/crypto/src/security/SecureRandom.cs index 6bc019481..ed0193e8d 100644 --- a/crypto/src/security/SecureRandom.cs +++ b/crypto/src/security/SecureRandom.cs @@ -28,7 +28,12 @@ namespace Org.BouncyCastle.Security // Even though Ticks has at most 8 or 14 bits of entropy, there's no harm in adding it. sr.SetSeed(DateTime.Now.Ticks); - + // In addition to Ticks and ThreadedSeedGenerator, also seed from CryptoApiRandomGenerator + CryptoApiRandomGenerator systemRNG = new CryptoApiRandomGenerator(); + byte[] systemSeed = new byte[32]; + systemRNG.NextBytes(systemSeed); + sr.SetSeed(systemSeed); + Array.Clear(systemSeed,0,systemSeed.Length); // 32 will be enough when ThreadedSeedGenerator is fixed. Until then, ThreadedSeedGenerator returns low // entropy, and this is not sufficient to be secure. http://www.bouncycastle.org/csharpdevmailarchive/msg00814.html sr.SetSeed(new ThreadedSeedGenerator().GenerateSeed(32, true)); -- cgit 1.4.1