/// <summary> /// Initializes a new instance of the <see cref="HmacAuthenticationParameters"/> class. /// </summary> /// <param name="algorithm">The hash algorithm to use for the computation.</param> /// <param name="privateKey">The secret key for the hashed encryption. The key can be any length, but it is strongly recommended to use a size of either 64 bytes (for <see cref="HmacAlgorithmType.SHA1"/> and <see cref="HmacAlgorithmType.SHA256"/>) or 128 bytes (for <see cref="HmacAlgorithmType.SHA384"/> and <see cref="HmacAlgorithmType.SHA512"/>).</param> /// <param name="message">The <see cref="string"/> value to compute a hash code for.</param> internal HmacAuthenticationParameters(HmacAlgorithmType algorithm, byte[] privateKey, string message) { Algorithm = algorithm; Message = message; PrivateKey = privateKey; }
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)); }