LaDeak.HttpMessageSigner.AspNetCore 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package LaDeak.HttpMessageSigner.AspNetCore --version 0.2.0
                    
NuGet\Install-Package LaDeak.HttpMessageSigner.AspNetCore -Version 0.2.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="LaDeak.HttpMessageSigner.AspNetCore" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LaDeak.HttpMessageSigner.AspNetCore" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="LaDeak.HttpMessageSigner.AspNetCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LaDeak.HttpMessageSigner.AspNetCore --version 0.2.0
                    
#r "nuget: LaDeak.HttpMessageSigner.AspNetCore, 0.2.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.
#:package LaDeak.HttpMessageSigner.AspNetCore@0.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LaDeak.HttpMessageSigner.AspNetCore&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=LaDeak.HttpMessageSigner.AspNetCore&version=0.2.0
                    
Install as a Cake Tool

HttpMessageSigner

ASP.NET Core middleware for signing HTTP responses with HTTP Message Signatures (RFC 9421). It can also calculate a response Content-Digest (RFC 9530) and include it in the signature.

This is useful in the following scenarios:

  • A message is saved for temporal reference. The source and integrity of the message can be validated across databases reads and writes that are separate events in time. For example, signatures in a legal archive preserves the integrity of the message.
  • Protection against intermediaries in transport security. It provides end-to-end integrity. For example, protection against early TLS termination or compromised intermediaries (API gateways).
  • Signed business assertions.
  • Response binding to a request.

Getting started

Install

Add the NuGet package to your ASP.NET Core project:

dotnet add package LaDeak.HttpMessageSigner.AspNetCore

The package targets .NET and uses the ASP.NET Core framework.

Configure ASP.NET Core

The middleware needs a signing certificate with a private key. Configure its path and password using your normal configuration provider (for example, environment variables Signing__CertificatePath and Signing__CertificatePassword). Keep production private keys and passwords in a secure store; do not commit them to source control.

using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using HttpMessageSigner.AspNetCore;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSignatureGenerator(x =>
{
    x.Algorithm = "ecdsa-p256-sha256";
    x.Components = ["@method", "@path", "@authority", "@scheme", "@status", "Content-Digest"];
    x.IncludeCreated = true;
    x.ContentDigestHashAlgorithm = System.Security.Cryptography.HashAlgorithmName.SHA256;
    x.KeyId = "ecdsa256";
    x.SigningCertificate = X509CertificateLoader.LoadPkcs12FromFile("<path to certificate>", "<cert password>", X509KeyStorageFlags.EphemeralKeySet | X509KeyStorageFlags.Exportable);
});

var app = builder.Build();
app.UseHttpsRedirection();
app.UseSignatureGeneration();

app.MapGet("/hello", () => new { Message = "Hello, signed world!" });

app.Run();

The middleware hashes the response body to produce Content-Digest and signs it together with the configured request and response components. Where the server supports response trailers, the digest and signature are written as trailers, allowing the response body to stream without buffering (for example, over HTTP/2). For HTTP/1.1 responses, the middleware buffers the response so it can calculate the digest and add the signature before sending the response.

Validate signatures

Register the signature validator and add its middleware to the ASP.NET Core pipeline. Configure SignatureName for the signature label used in Signature and Signature-Input, and add each public certificate using the keyid value declared by the signer.

using System.Security.Cryptography.X509Certificates;
using HttpMessageSigner.AspNetCore;

builder.Services.AddSignatureValidator(x =>
{
    x.SignatureName = "s0";
    x.Certificates.Add("ecdsa256", X509CertificateLoader.LoadPkcs12FromFile(
        "<path to certificate>",
        "<cert password>",
        X509KeyStorageFlags.EphemeralKeySet));
});

var app = builder.Build();
app.UseHttpsRedirection();
app.UseSignatureValidation();

app.MapPost("/submit", async (HttpContext context) =>
{
    // Consume the request body before validating when the signature includes
    // Content-Digest, so the digest can be calculated over the complete body.
    await context.Request.BodyReader.CopyToAsync(Stream.Null);

    var validator = context.Features.GetRequiredFeature<ISignatureValidatiorFeature>();
    if (!validator.ValidateSignature())
        return Results.Unauthorized();

    return Results.Ok();
});

app.Run();

For endpoint filters, add SignatureValidatingFilter to an endpoint instead:

app.MapPost("/submit", (MyRequest value) => Results.Ok())
   .AddEndpointFilter<SignatureValidatingFilter>();

ValidateSignature() validates the signature parameters and cryptographic value, as well as Content-Digest when a digest is included. Unsupported or invalid signatures return false; application code is responsible for returning an appropriate response, such as 401 Unauthorized.

Unsupported component names

The library does not support the RFC 9421 derived components @query-param and @request-target. Configuring either component, including a variant such as @query-param;name="foo", throws NotSupportedException.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net11.0

    • No dependencies.

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
0.3.1 0 12/2/2026
0.3.0 0 12/2/2026
0.2.0 68 11/29/2026
0.1.0 98 11/23/2026
0.0.1 98 11/23/2026
0.0.1-prerelease01 94 11/22/2026