//-----------------------------------------------------------------------
//
// Copyright (c) Andrew Arnott. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OAuth {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
///
/// A delegating HTTP handler that signs outgoing HTTP requests
/// with an HMAC-SHA1 signature.
///
public class OAuth1HmacSha1HttpMessageHandler : OAuth1HttpMessageHandlerBase {
///
/// Initializes a new instance of the class.
///
public OAuth1HmacSha1HttpMessageHandler() {
}
///
/// Initializes a new instance of the class.
///
/// The inner handler which is responsible for processing the HTTP response messages.
public OAuth1HmacSha1HttpMessageHandler(HttpMessageHandler innerHandler)
: base(innerHandler) {
}
///
/// Gets the signature method to include in the oauth_signature_method parameter.
///
///
/// The signature method.
///
protected override string SignatureMethod {
get { return "HMAC-SHA1"; }
}
///
/// Calculates the signature for the specified buffer.
///
/// The payload to calculate the signature for.
///
/// The signature.
///
protected override byte[] Sign(byte[] signedPayload) {
using (var algorithm = HMACSHA1.Create()) {
algorithm.Key = Encoding.ASCII.GetBytes(this.GetConsumerAndTokenSecretString());
return algorithm.ComputeHash(signedPayload);
}
}
}
}