//----------------------------------------------------------------------- // // 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.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; using Validation; /// /// A delegating HTTP handler that signs outgoing HTTP requests /// with an RSA-SHA1 signature. /// public class OAuth1RsaSha1HttpMessageHandler : OAuth1HttpMessageHandlerBase { /// /// Initializes a new instance of the class. /// public OAuth1RsaSha1HttpMessageHandler() { } /// /// Initializes a new instance of the class. /// /// The inner handler which is responsible for processing the HTTP response messages. public OAuth1RsaSha1HttpMessageHandler(HttpMessageHandler innerHandler) : base(innerHandler) { } /// /// Gets or sets the certificate used to sign outgoing messages. Used only by Consumers. /// public X509Certificate2 SigningCertificate { get; set; } /// /// Gets the signature method to include in the oauth_signature_method parameter. /// /// /// The signature method. /// protected override string SignatureMethod { get { return "RSA-SHA1"; } } /// /// Calculates the signature for the specified buffer. /// /// The payload to calculate the signature for. /// /// The signature. /// protected override byte[] Sign(byte[] signedPayload) { Verify.Operation(this.SigningCertificate != null, Strings.RequiredPropertyNotYetPreset); var provider = (RSACryptoServiceProvider)this.SigningCertificate.PrivateKey; byte[] binarySignature = provider.SignData(signedPayload, "SHA1"); return binarySignature; } } }