Exemplo n.º 1
0
        private static HashResult ComputeHashCore(Stream value, byte[] hash, byte[] sharedKey, HmacAlgorithmType algorithmType, bool leaveStreamOpen)
        {
            if (algorithmType > HmacAlgorithmType.SHA512 || algorithmType < HmacAlgorithmType.SHA1)
            {
                throw new ArgumentOutOfRangeException(nameof(algorithmType), "Specified argument was out of the range of valid values.");
            }

            HashAlgorithm algorithm;

            switch (algorithmType)
            {
            case HmacAlgorithmType.SHA1:
                goto default;

            case HmacAlgorithmType.SHA256:
                algorithm = new HMACSHA256(sharedKey);
                break;

            case HmacAlgorithmType.SHA384:
                algorithm = new HMACSHA384(sharedKey);
                break;

            case HmacAlgorithmType.SHA512:
                algorithm = new HMACSHA512(sharedKey);
                break;

            default:
                algorithm = new HMACSHA1(sharedKey);
                break;
            }

            return(HashUtility.ComputeHashCore(value, hash, leaveStreamOpen, algorithm));
        }
 /// <summary>
 /// Computes a hash value of the specified <paramref name="values"/>.
 /// </summary>
 /// <param name="values">The <see cref="string"/> sequence to compute a hash code for.</param>
 /// <param name="setup">The <see cref="StringHashOptions"/> which need to be configured.</param>
 /// <returns>A <see cref="HashResult"/> containing the computed hash value of the specified <paramref name="values"/>.</returns>
 public static HashResult ComputeHash(this string[] values, Action <StringHashOptions> setup = null)
 {
     return(HashUtility.ComputeHash(values, setup));
 }
 /// <summary>
 /// Computes a hash value of the specified <paramref name="value"/>.
 /// </summary>
 /// <param name="value">The object to compute a hash code for.</param>
 /// <param name="setup">The <see cref="HashOptions"/> which need to be configured.</param>
 /// <returns>A <see cref="HashResult"/> containing the computed hash value of the specified <paramref name="value"/>.</returns>
 public static HashResult ComputeHash(this object value, Action <HashOptions> setup = null)
 {
     return(HashUtility.ComputeHash(value, setup));
 }