//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Messaging {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using Validation;
///
/// HMAC-SHA algorithm names that can be passed to the method.
///
internal static class HmacAlgorithms {
///
/// The name of the HMAC-SHA1 algorithm.
///
internal const string HmacSha1 = "HMACSHA1";
///
/// The name of the HMAC-SHA256 algorithm.
///
internal const string HmacSha256 = "HMACSHA256";
///
/// The name of the HMAC-SHA384 algorithm.
///
internal const string HmacSha384 = "HMACSHA384";
///
/// The name of the HMAC-SHA512 algorithm.
///
internal const string HmacSha512 = "HMACSHA512";
///
/// Creates an HMAC-SHA algorithm with the specified name and key.
///
/// A name from the available choices in the static const members of this class.
/// The secret key used as the HMAC.
/// The HMAC algorithm instance.
internal static HMAC Create(string algorithmName, byte[] key) {
Requires.NotNullOrEmpty(algorithmName, "algorithmName");
Requires.NotNull(key, "key");
HMAC hmac = HMAC.Create(algorithmName);
try {
hmac.Key = key;
return hmac;
} catch {
hmac.Dispose();
throw;
}
}
}
}