summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Core/Messaging/HmacAlgorithms.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2012-10-14 19:58:54 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2012-10-14 19:58:54 -0700
commit1147c2afd97ce408f2e4d08458ca68b108c35b1e (patch)
treed812ae4d013142db03091abf61742a3753eb7ed2 /src/DotNetOpenAuth.Core/Messaging/HmacAlgorithms.cs
parent0484ade3bd35282c8b30cfa27730498ab5168859 (diff)
parent321267ee6a54e917395694f270d3f6fe7fae3c51 (diff)
downloadDotNetOpenAuth-1147c2afd97ce408f2e4d08458ca68b108c35b1e.zip
DotNetOpenAuth-1147c2afd97ce408f2e4d08458ca68b108c35b1e.tar.gz
DotNetOpenAuth-1147c2afd97ce408f2e4d08458ca68b108c35b1e.tar.bz2
Merge branch 'v4.1'
Diffstat (limited to 'src/DotNetOpenAuth.Core/Messaging/HmacAlgorithms.cs')
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/HmacAlgorithms.cs60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.Core/Messaging/HmacAlgorithms.cs b/src/DotNetOpenAuth.Core/Messaging/HmacAlgorithms.cs
new file mode 100644
index 0000000..872b4ac
--- /dev/null
+++ b/src/DotNetOpenAuth.Core/Messaging/HmacAlgorithms.cs
@@ -0,0 +1,60 @@
+//-----------------------------------------------------------------------
+// <copyright file="HmacAlgorithms.cs" company="Outercurve Foundation">
+// Copyright (c) Outercurve Foundation. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Messaging {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Security.Cryptography;
+ using System.Text;
+
+ /// <summary>
+ /// HMAC-SHA algorithm names that can be passed to the <see cref="HMAC.Create(string)"/> method.
+ /// </summary>
+ internal static class HmacAlgorithms {
+ /// <summary>
+ /// The name of the HMAC-SHA1 algorithm.
+ /// </summary>
+ internal const string HmacSha1 = "HMACSHA1";
+
+ /// <summary>
+ /// The name of the HMAC-SHA256 algorithm.
+ /// </summary>
+ internal const string HmacSha256 = "HMACSHA256";
+
+ /// <summary>
+ /// The name of the HMAC-SHA384 algorithm.
+ /// </summary>
+ internal const string HmacSha384 = "HMACSHA384";
+
+ /// <summary>
+ /// The name of the HMAC-SHA512 algorithm.
+ /// </summary>
+ internal const string HmacSha512 = "HMACSHA512";
+
+ /// <summary>
+ /// Creates an HMAC-SHA algorithm with the specified name and key.
+ /// </summary>
+ /// <param name="algorithmName">A name from the available choices in the static const members of this class.</param>
+ /// <param name="key">The secret key used as the HMAC.</param>
+ /// <returns>The HMAC algorithm instance.</returns>
+ 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 {
+#if CLR4
+ hmac.Dispose();
+#endif
+ throw;
+ }
+ }
+ }
+}