Пример #1
0
        internal static HashAlgorithm ObjToHashAlgorithm(object hashAlg)
        {
            if (hashAlg == null)
            {
                throw new ArgumentNullException("hashAlg");
            }
            HashAlgorithm algorithm = null;

            if (hashAlg is string)
            {
                algorithm = (HashAlgorithm)CryptoConfig.CreateFromName((string)hashAlg);
                if (algorithm == null)
                {
                    string name = X509Utils._GetFriendlyNameFromOid((string)hashAlg);
                    if (name != null)
                    {
                        algorithm = (HashAlgorithm)CryptoConfig.CreateFromName(name);
                    }
                }
            }
            else if (hashAlg is HashAlgorithm)
            {
                algorithm = (HashAlgorithm)hashAlg;
            }
            else if (hashAlg is Type)
            {
                algorithm = (HashAlgorithm)CryptoConfig.CreateFromName(hashAlg.ToString());
            }
            if (algorithm == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidValue"));
            }
            return(algorithm);
        }