Beispiel #1
0
        /// <summary>
        /// Given an item from the Hashes enumeration, get the HashAlgorithm associated with it.
        /// </summary>
        /// <param name="hash">A Hashes enumeration item</param>
        /// <returns>The HashAlgorithm that matches the enumerated hash</returns>
        private static HashAlgorithm GetHashAlgorithm(Hashes hash)
        {
            HashAlgorithm hasher = null;

            switch (hash)
            {
            case Hashes.MD5:
                hasher = new MD5CryptoServiceProvider();
                break;

            case Hashes.SHA1:
                hasher = new SHA1CryptoServiceProvider();
                break;

            case Hashes.SHA256:
                hasher = new SHA256Managed();
                break;

            case Hashes.SHA384:
                hasher = new SHA384Managed();
                break;

            case Hashes.SHA512:
                hasher = new SHA512Managed();
                break;

            case Hashes.RIPEMD160:
                hasher = new RIPEMD160Managed();
                break;

            case Hashes.Whirlpool:
                hasher = new WhirlpoolManaged();
                break;

            case Hashes.Tiger:
                hasher = new TigerManaged();
                break;

            // If we didn't get something we expected, default to MD5:
            default:
                hasher = new MD5CryptoServiceProvider();
                break;
            }
            return(hasher);
        }
 /// <summary>
 /// Given an item from the Hashes enumeration, get the HashAlgorithm associated with it.
 /// </summary>
 /// <param name="hash">A Hashes enumeration item</param>
 /// <returns>The HashAlgorithm that matches the enumerated hash</returns>
 private static HashAlgorithm GetHashAlgorithm(Hashes hash)
 {
     HashAlgorithm hasher = null;
     switch (hash)
     {
         case Hashes.MD5:
             hasher = new MD5CryptoServiceProvider();
             break;
         case Hashes.SHA1:
             hasher = new SHA1CryptoServiceProvider();
             break;
         case Hashes.SHA256:
             hasher = new SHA256Managed();
             break;
         case Hashes.SHA384:
             hasher = new SHA384Managed();
             break;
         case Hashes.SHA512:
             hasher = new SHA512Managed();
             break;
         case Hashes.RIPEMD160:
             hasher = new RIPEMD160Managed();
             break;
         case Hashes.Whirlpool:
             hasher = new WhirlpoolManaged();
             break;
         case Hashes.Tiger:
             hasher = new TigerManaged();
             break;
         // If we didn't get something we expected, default to MD5:
         default:
             hasher = new MD5CryptoServiceProvider();
             break;
     }
     return hasher;
 }