コード例 #1
0
        /// <summary>
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="algorithm">
        /// </param>
        /// <returns>
        /// </returns>
        /// <exception cref="InvalidOperationException">
        /// </exception>
        private static HashAlgorithm CreateSha512HashAlgorithm(String algorithm)
        {
            HashAlgorithm result;

            if (String.IsNullOrWhiteSpace(algorithm))
            {
                result = SHA512.Create();
            }
            else
            {
                result = SHA512.Create(algorithm);
            }

            if (result is null)
            {
                throw MethodExtension.GetInvalidOperationException(Method.Sha512, algorithm);
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="method">
        /// </param>
        /// <param name="algorithm">
        /// </param>
        /// <returns>
        /// </returns>
        /// <seealso cref="Method"/>
        /// <seealso cref="MD5.Create()"/>
        /// <seealso cref="SHA1.Create()"/>
        /// <seealso cref="SHA256.Create()"/>
        /// <seealso cref="SHA384.Create()"/>
        /// <seealso cref="SHA512.Create()"/>
        /// <seealso cref="MD5.Create(String)"/>
        /// <seealso cref="SHA1.Create(String)"/>
        /// <seealso cref="SHA256.Create(String)"/>
        /// <seealso cref="SHA384.Create(String)"/>
        /// <seealso cref="SHA512.Create(String)"/>
        /// <exception cref="NotSupportedException">
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// </exception>
        internal static HashAlgorithm Create(this Method method, String algorithm)
        {
            switch (method)
            {
            case Method.Md5:
                return(MethodExtension.CreateMd5HashAlgorithm(algorithm));

            case Method.Sha1:
                return(MethodExtension.CreateSha1HashAlgorithm(algorithm));

            case Method.Sha256:
                return(MethodExtension.CreateSha256HashAlgorithm(algorithm));

            case Method.Sha384:
                return(MethodExtension.CreateSha384HashAlgorithm(algorithm));

            case Method.Sha512:
                return(MethodExtension.CreateSha512HashAlgorithm(algorithm));

            default:
                throw MethodExtension.GetNotSupportedException(method, algorithm);
            }
        }