コード例 #1
0
        private HashAlgorithm GetHashAlgorithm()
        {
            HashAlgorithm algorithm = null;

            try
            {
                Type type = Type.GetType(algorithmType);
                algorithm = Activator.CreateInstance(type, true) as HashAlgorithm;
                KeyedHashAlgorithm keyedHashAlgorithm = algorithm as KeyedHashAlgorithm;
                if ((null != keyedHashAlgorithm) && (key != null))
                {
                    keyedHashAlgorithm.Key = key;
                }
            }
            catch (Exception ex)
            {
                CryptographyUtility.LogCryptographyException(ex);
                throw new CryptographicException(SR.ExceptionCreatingHashAlgorithmInstance);
            }

            if (algorithm == null)
            {
                throw new CryptographicException(SR.ExceptionCastingHashAlgorithmInstance);
            }

            return(algorithm);
        }
コード例 #2
0
        private static SymmetricAlgorithm GetSymmetricAlgorithm(string algorithmType)
        {
            SymmetricAlgorithm sa = null;

            try
            {
                Type type = Type.GetType(algorithmType, true);
                sa = Activator.CreateInstance(type) as SymmetricAlgorithm;
            }
            catch (Exception ex)
            {
                // We want to supress any type of exception here for security reasons.
                CryptographyUtility.LogCryptographyException(ex);
                throw new CryptographicException(SR.ExceptionCreatingSymmetricAlgorithmInstance);
            }

            if (sa == null)
            {
                throw new CryptographicException(SR.ExceptionCastingSymmetricAlgorithmInstance);
            }

            return(sa);
        }