From a0d33a340a7445f466aedcaafdbf7f2f7e738d9a Mon Sep 17 00:00:00 2001 From: Edward Ned Harvey Date: Tue, 5 Aug 2014 11:31:07 -0400 Subject: GetInstance() returns a seeded instance. If you want an unseeded instance, you must use the unseeded ctor in which you supply your own generator --- crypto/src/security/SecureRandom.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'crypto/src/security/SecureRandom.cs') diff --git a/crypto/src/security/SecureRandom.cs b/crypto/src/security/SecureRandom.cs index 055162f1f..ef932ee8c 100644 --- a/crypto/src/security/SecureRandom.cs +++ b/crypto/src/security/SecureRandom.cs @@ -46,24 +46,20 @@ namespace Org.BouncyCastle.Security public static SecureRandom GetInstance( string algorithm) { - // TODO Compared to JDK, we don't auto-seed if the client forgets - problem? - // TODO Support all digests more generally, by stripping PRNG and calling DigestUtilities? string drgName = Platform.ToUpperInvariant(algorithm); - IRandomGenerator drg = null; if (drgName == "SHA1PRNG") { - drg = sha1Generator; + SecureRandom newPrng = new SecureRandom(sha1Generator); + newPrng.SetSeed(GetSeed(20)); + return newPrng; } else if (drgName == "SHA256PRNG") { - drg = sha256Generator; - } - - if (drg != null) - { - return new SecureRandom(drg); + SecureRandom newPrng = new SecureRandom(sha256Generator); + newPrng.SetSeed(GetSeed(32)); + return newPrng; } throw new ArgumentException("Unrecognised PRNG algorithm: " + algorithm, "algorithm"); -- cgit 1.5.1