| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- using System.Security.Cryptography;
- namespace Renci.SshNet.Security.Cryptography
- {
- internal static class HashAlgorithmFactory
- {
- public static RandomNumberGenerator CreateRandomNumberGenerator()
- {
- #if FEATURE_RNG_CRYPTO
- return new RNGCryptoServiceProvider();
- #else
- return RandomNumberGenerator.Create();
- #endif
- }
- #if FEATURE_HASH_MD5
- public static System.Security.Cryptography.MD5 CreateMD5()
- {
- return System.Security.Cryptography.MD5.Create();
- }
- #else
- public static Renci.Security.Cryptography.MD5 CreateMD5()
- {
- return new Renci.Security.Cryptography.MD5();
- }
- #endif // FEATURE_HASH_MD5
- #if FEATURE_HASH_SHA1
- public static System.Security.Cryptography.SHA1 CreateSHA1()
- {
- return new System.Security.Cryptography.SHA1Managed();
- }
- #else
- public static Renci.Security.Cryptography.SHA1 CreateSHA1()
- {
- return new Renci.Security.Cryptography.SHA1();
- }
- #endif
- #if FEATURE_HASH_SHA256
- public static System.Security.Cryptography.SHA256 CreateSHA256()
- {
- return new System.Security.Cryptography.SHA256Managed();
- }
- #else
- public static Renci.Security.Cryptography.SHA256 CreateSHA256()
- {
- return new Renci.Security.Cryptography.SHA256();
- }
- #endif
- #if FEATURE_HASH_SHA384
- public static System.Security.Cryptography.SHA384 CreateSHA384()
- {
- return new System.Security.Cryptography.SHA384Managed();
- }
- #else
- public static Renci.Security.Cryptography.SHA384 CreateSHA384()
- {
- return new Renci.Security.Cryptography.SHA384();
- }
- #endif
- #if FEATURE_HASH_SHA512
- public static System.Security.Cryptography.SHA512 CreateSHA512()
- {
- return new System.Security.Cryptography.SHA512Managed();
- }
- #else
- public static Renci.Security.Cryptography.SHA512 CreateSHA512()
- {
- return new Renci.Security.Cryptography.SHA512();
- }
- #endif
- #if FEATURE_HASH_RIPEMD160
- public static System.Security.Cryptography.RIPEMD160 CreateRIPEMD160()
- {
- return new System.Security.Cryptography.RIPEMD160Managed();
- }
- #else
- public static Renci.Security.Cryptography.RIPEMD160 CreateRIPEMD160()
- {
- return new Renci.Security.Cryptography.RIPEMD160();
- }
- #endif // FEATURE_HASH_RIPEMD160
- #if FEATURE_HMAC_MD5
- public static System.Security.Cryptography.HMACMD5 CreateHMACMD5(byte[] key)
- {
- return new System.Security.Cryptography.HMACMD5(key);
- }
- public static HMACMD5 CreateHMACMD5(byte[] key, int hashSize)
- {
- return new HMACMD5(key, hashSize);
- }
- #else
- public static Renci.Security.Cryptography.HMACMD5 CreateHMACMD5(byte[] key)
- {
- return new Renci.Security.Cryptography.HMACMD5(key);
- }
- public static Renci.Security.Cryptography.HMACMD5 CreateHMACMD5(byte[] key, int hashSize)
- {
- return new Renci.Security.Cryptography.HMACMD5(key, hashSize);
- }
- #endif // FEATURE_HMAC_MD5
- #if FEATURE_HMAC_SHA1
- public static System.Security.Cryptography.HMACSHA1 CreateHMACSHA1(byte[] key)
- {
- return new System.Security.Cryptography.HMACSHA1(key);
- }
- public static HMACSHA1 CreateHMACSHA1(byte[] key, int hashSize)
- {
- return new HMACSHA1(key, hashSize);
- }
- #else
- public static Renci.Security.Cryptography.HMACSHA1 CreateHMACSHA1(byte[] key)
- {
- return new Renci.Security.Cryptography.HMACSHA1(key);
- }
- public static Renci.Security.Cryptography.HMACSHA1 CreateHMACSHA1(byte[] key, int hashSize)
- {
- return new Renci.Security.Cryptography.HMACSHA1(key, hashSize);
- }
- #endif // FEATURE_HMAC_SHA1
- #if FEATURE_HMAC_SHA256
- public static System.Security.Cryptography.HMACSHA256 CreateHMACSHA256(byte[] key)
- {
- return new System.Security.Cryptography.HMACSHA256(key);
- }
- public static HMACSHA256 CreateHMACSHA256(byte[] key, int hashSize)
- {
- return new HMACSHA256(key, hashSize);
- }
- #else
- public static Renci.Security.Cryptography.HMACSHA256 CreateHMACSHA256(byte[] key)
- {
- return new Renci.Security.Cryptography.HMACSHA256(key);
- }
- public static Renci.Security.Cryptography.HMACSHA256 CreateHMACSHA256(byte[] key, int hashSize)
- {
- return new Renci.Security.Cryptography.HMACSHA256(key, hashSize);
- }
- #endif // FEATURE_HMAC_SHA256
- #if FEATURE_HMAC_SHA384
- public static System.Security.Cryptography.HMACSHA384 CreateHMACSHA384(byte[] key)
- {
- return new System.Security.Cryptography.HMACSHA384(key);
- }
- public static HMACSHA384 CreateHMACSHA384(byte[] key, int hashSize)
- {
- return new HMACSHA384(key, hashSize);
- }
- #else
- public static Renci.Security.Cryptography.HMACSHA384 CreateHMACSHA384(byte[] key)
- {
- return new Renci.Security.Cryptography.HMACSHA384(key);
- }
- public static Renci.Security.Cryptography.HMACSHA384 CreateHMACSHA384(byte[] key, int hashSize)
- {
- return new Renci.Security.Cryptography.HMACSHA384(key, hashSize);
- }
- #endif // FEATURE_HMAC_SHA384
- #if FEATURE_HMAC_SHA512
- public static System.Security.Cryptography.HMACSHA512 CreateHMACSHA512(byte[] key)
- {
- return new System.Security.Cryptography.HMACSHA512(key);
- }
- public static HMACSHA512 CreateHMACSHA512(byte[] key, int hashSize)
- {
- return new HMACSHA512(key, hashSize);
- }
- #else
- public static Renci.Security.Cryptography.HMACSHA512 CreateHMACSHA512(byte[] key)
- {
- return new Renci.Security.Cryptography.HMACSHA512(key);
- }
- public static Renci.Security.Cryptography.HMACSHA512 CreateHMACSHA512(byte[] key, int hashSize)
- {
- return new Renci.Security.Cryptography.HMACSHA512(key, hashSize);
- }
- #endif // FEATURE_HMAC_SHA512
- #if FEATURE_HMAC_RIPEMD160
- public static System.Security.Cryptography.HMACRIPEMD160 CreateHMACRIPEMD160(byte[] key)
- {
- return new System.Security.Cryptography.HMACRIPEMD160(key);
- }
- #else
- public static Renci.Security.Cryptography.HMACRIPEMD160 CreateHMACRIPEMD160(byte[] key)
- {
- return new Renci.Security.Cryptography.HMACRIPEMD160(key);
- }
- #endif // FEATURE_HMAC_RIPEMD160
- }
- }
|