PayNL.RequestSigning 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package PayNL.RequestSigning --version 2.0.0
NuGet\Install-Package PayNL.RequestSigning -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PayNL.RequestSigning" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PayNL.RequestSigning --version 2.0.0
#r "nuget: PayNL.RequestSigning, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PayNL.RequestSigning as a Cake Addin
#addin nuget:?package=PayNL.RequestSigning&version=2.0.0

// Install PayNL.RequestSigning as a Cake Tool
#tool nuget:?package=PayNL.RequestSigning&version=2.0.0

Request Signing

This package adds functionality to sign & verify requests sent by the Pay. platform.

Usage

The RequestSigningService simplifies both signing and verifying requests, avoiding the need for manual class instantiation.

The constructor function of this service requires an array of SingingMethods that you wish to support. Each signing method has different needs and functionality, and which one(s) you opt to support falls under your discretion.

By providing the service with the array of these chosen methods, the service can handle the configuration and functionality. This decouples the setup process from your main application logic, allowing a more streamlined integration.

Signing

The below code snippet shows the basis of singing a request using this package:

using PayRequestSigningSdk;
 
// Generate
var signingService = new RequestSigningService(new List<IRequestSigningMethod>()
{
    new HmacSignature(new SignatureKeyRepository() ),
});

var request = new HttpRequestMessage(new HttpMethod("GET"), "http://localhost:5160/WeatherForecast");

var signed = signingService.Sign(request, "key", "sha512", "HMAC");
var http = new HttpClient();
var response = await http.SendAsync(signed);
Console.WriteLine($"Response: {response.Content.ReadAsStringAsync().Result}");
Console.WriteLine($"Signature: {signed.Headers.GetValues(IRequestSigningMethod.SignatureHeader).First()}");

// Verify
var verified = await signingService.VerifyAndDecodeAsync(signed);
Console.WriteLine($"Verify result: {JsonSerializer.Serialize(verified)}");

Exception handling

The request signing service and the underlying signing / verifying methods may throw exceptions when unexpected values are encountered, these are:

  • SignatureKeyNotFound, this exception must be thrown when the implementation of the ISignatureKeyRepository can not find the key based on the provided id;
  • UnknownSigningMethodException, this exception will be thrown by the singing / verifying methods when they are requested to sign / verify a request with an algorithm they do not support;
  • UnsupportedHashingAlgorithmException, this exception will be thrown by the RequestSigningService when it is requested to sign / verify a request with a method it doesn't support.
  • BodyDecodeException, this exception will be thrown if the body of the HttpMessage passed to the 'VerifyAndDecodeAsync' method is not in the expected format, if request is not GET.
  • QueryUrlDecodeException, this exception will be thrown if the query string of the HttpMessage passed to the 'VerifyAndDecodeAsync' method is not in the expected format, if request is GET.
  • InvalidSignatureException, this exception will be thrown if the process succeedes, but the resulting signature does not match the one provided by the request.

Supported Signing / Verifying methods

HMAC

The HmacSignature class enables the signing and verification of requests made with HMAC signatures. To utilize this class's method, a single argument is required for its constructor. This argument is of type IHmacSignatureKeyRepository.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 84 4/12/2024
2.1.0 81 4/10/2024
2.0.0 89 4/9/2024
1.1.0.1 89 4/8/2024
1.1.0 1,574 3/25/2024
1.0.0 4,605 1/4/2024

First release