summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Core/Messaging/HmacAlgorithms.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2012-07-18 08:11:59 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2012-07-18 08:11:59 -0700
commit8837d7fb4d61525c9bddc4fed8300a1bb9978ffa (patch)
treec1da80e194e6dd4b1cfce26daf989b37f901998b /src/DotNetOpenAuth.Core/Messaging/HmacAlgorithms.cs
parent72a8bc9b9801202e6bf3471fb4527a1bccb99cea (diff)
downloadDotNetOpenAuth-8837d7fb4d61525c9bddc4fed8300a1bb9978ffa.zip
DotNetOpenAuth-8837d7fb4d61525c9bddc4fed8300a1bb9978ffa.tar.gz
DotNetOpenAuth-8837d7fb4d61525c9bddc4fed8300a1bb9978ffa.tar.bz2
Replaces explicit crypto algorithm use with factories.
Fixes #47 which requires that FIPS compliance be an option.
Diffstat (limited to 'src/DotNetOpenAuth.Core/Messaging/HmacAlgorithms.cs')
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/HmacAlgorithms.cs58
1 files changed, 58 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..41dce81
--- /dev/null
+++ b/src/DotNetOpenAuth.Core/Messaging/HmacAlgorithms.cs
@@ -0,0 +1,58 @@
+//-----------------------------------------------------------------------
+// <copyright file="HmacAlgorithmNames.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"/> 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 {
+ hmac.Dispose();
+ throw;
+ }
+ }
+ }
+}