diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/DotNetOpenAuth.OAuth.Consumer/DotNetOpenAuth.OAuth.Consumer.csproj | 1 | ||||
-rw-r--r-- | src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1RsaSha1HttpMessageHandler.cs | 51 |
2 files changed, 52 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.OAuth.Consumer/DotNetOpenAuth.OAuth.Consumer.csproj b/src/DotNetOpenAuth.OAuth.Consumer/DotNetOpenAuth.OAuth.Consumer.csproj index 3d43a38..8c2cb18 100644 --- a/src/DotNetOpenAuth.OAuth.Consumer/DotNetOpenAuth.OAuth.Consumer.csproj +++ b/src/DotNetOpenAuth.OAuth.Consumer/DotNetOpenAuth.OAuth.Consumer.csproj @@ -27,6 +27,7 @@ <Compile Include="OAuth\DesktopConsumer.cs" /> <Compile Include="OAuth\OAuth1HmacSha1HttpMessageHandler.cs" /> <Compile Include="OAuth\OAuth1HttpMessageHandlerBase.cs" /> + <Compile Include="OAuth\OAuth1RsaSha1HttpMessageHandler.cs" /> <Compile Include="OAuth\WebConsumer.cs" /> <Compile Include="Properties\AssemblyInfo.cs"> <SubType> diff --git a/src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1RsaSha1HttpMessageHandler.cs b/src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1RsaSha1HttpMessageHandler.cs new file mode 100644 index 0000000..cf0fb9c --- /dev/null +++ b/src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1RsaSha1HttpMessageHandler.cs @@ -0,0 +1,51 @@ +//----------------------------------------------------------------------- +// <copyright file="OAuth1RsaSha1HttpMessageHandler.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.OAuth { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Security.Cryptography; + using System.Security.Cryptography.X509Certificates; + using System.Text; + using System.Threading.Tasks; + using Validation; + + /// <summary> + /// A delegating HTTP handler that signs outgoing HTTP requests + /// with an RSA-SHA1 signature. + /// </summary> + public class OAuth1RsaSha1HttpMessageHandler : OAuth1HttpMessageHandlerBase { + /// <summary> + /// Gets or sets the certificate used to sign outgoing messages. Used only by Consumers. + /// </summary> + public X509Certificate2 SigningCertificate { get; set; } + + /// <summary> + /// Calculates the signature for the specified buffer. + /// </summary> + /// <param name="signedPayload">The payload to calculate the signature for.</param> + /// <returns> + /// The signature. + /// </returns> + 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; + } + + /// <summary> + /// Gets the signature method to include in the oauth_signature_method parameter. + /// </summary> + /// <value> + /// The signature method. + /// </value> + protected override string SignatureMethod { + get { return "RSA-SHA1"; } + } + } +} |