//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOAuth.ChannelElements { using System; using System.Security.Cryptography; using System.Text; /// /// A binding element that signs outgoing messages and verifies the signature on incoming messages. /// public class HmacSha1SigningBindingElement : SigningBindingElementBase { /// /// Initializes a new instance of the class /// public HmacSha1SigningBindingElement() : base("HMAC-SHA1") { } /// /// Calculates a signature for a given message. /// /// The message to sign. /// The signature for the message. /// /// This method signs the message per OAuth 1.0 section 9.2. /// protected override string GetSignature(ITamperResistantOAuthMessage message) { string key = GetConsumerAndTokenSecretString(message); HashAlgorithm hasher = new HMACSHA1(Encoding.ASCII.GetBytes(key)); string baseString = ConstructSignatureBaseString(message); Logger.DebugFormat("Signing message with signature base string: {0}", baseString); byte[] digest = hasher.ComputeHash(Encoding.ASCII.GetBytes(baseString)); return Convert.ToBase64String(digest); } } }