Org.BouncyCastle.Security.SecureRandom.GetInstance C# (CSharp) Method

GetInstance() public static method

public static GetInstance ( string algorithm ) : SecureRandom
algorithm string
return SecureRandom
		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;
			}
			else if (drgName == "SHA256PRNG")
			{
				drg = sha256Generator;
			}

			if (drg != null)
			{
				return new SecureRandom(drg);
			}

			throw new ArgumentException("Unrecognised PRNG algorithm: " + algorithm, "algorithm");
		}

Usage Example

Esempio n. 1
0
 public static SecureRandom GetInstance(string algorithm)
 {
     return(SecureRandom.GetInstance(algorithm, true));
 }