HardenLabs.Hmac 1.1.0

dotnet add package HardenLabs.Hmac --version 1.1.0
                    
NuGet\Install-Package HardenLabs.Hmac -Version 1.1.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="HardenLabs.Hmac" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HardenLabs.Hmac" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="HardenLabs.Hmac" />
                    
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 HardenLabs.Hmac --version 1.1.0
                    
#r "nuget: HardenLabs.Hmac, 1.1.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 HardenLabs.Hmac@1.1.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=HardenLabs.Hmac&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=HardenLabs.Hmac&version=1.1.0
                    
Install as a Cake Tool

HardenLabs.Hmac

Cross-language HMAC-SHA256 request signing with a defined canonical string format. Guaranteed identical signatures across C#, Python, TypeScript, and Go.

Installation

dotnet add package HardenLabs.Hmac
dotnet add package HardenLabs.Hmac.AspNetCore  # for middleware

Quick Start — Server (ASP.NET Core)

using HardenLabs.Hmac;
using HardenLabs.Hmac.AspNetCore;

var config = new HmacConfig
{
    SignedHeaders = SignedHeadersConfig.Default,
    TimestampToleranceSeconds = 30,
    Clients = new Dictionary<string, HmacClientIdentity>
    {
        ["order-service"] = new HmacClientIdentity { SharedSecret = "orders-base64-secret" },
        ["payment-service"] = new HmacClientIdentity { SharedSecret = "payments-base64-secret" },
    },
};

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHardenHmac(config);

var app = builder.Build();
app.UseRouting();
app.UseHardenHmac();

// Protected — requires valid HMAC signature
app.MapGet("/api/hello", () => Results.Ok(new { message = "Authenticated!" }))
    .WithMetadata(new HmacValidateAttribute());

// Unprotected — no attribute, no HMAC required
app.MapGet("/health", () => Results.Ok(new { status = "healthy" }));

app.Run();

Endpoints are not validated by default — use [HmacValidate] to opt in. Use [SkipHmacValidate] on actions to exempt them when the controller is protected.

Public API — Server

Type Description
HmacValidateAttribute Opt-in HMAC validation for controllers or actions
SkipHmacValidateAttribute Exempt actions from validation when controller is protected
UseHardenHmac() Register middleware in the pipeline (after UseRouting())
AddHardenHmac(config) Register HMAC services for DI
AddHardenHmac(configuration) Register from IConfiguration section

Quick Start — Client (HttpClient)

using HardenLabs.Hmac;
using HardenLabs.Hmac.AspNetCore;

var config = new HmacConfig
{
    SignedHeaders = SignedHeadersConfig.Default,
    Targets = new Dictionary<string, HmacTargetConfig>
    {
        ["order-service"] = new HmacTargetConfig
        {
            BaseUrl = "https://orders.example.com",
            SharedSecret = "orders-base64-secret",
        },
    },
};

var factory = new HardenHmacClientFactory(config);
var client = factory.CreateClient("order-service"); // BaseAddress + signing pre-configured
var response = await client.GetAsync("/api/hello");  // automatically signed

Configuration from appsettings.json

{
  "HardenHmac": {
    "TimestampToleranceSeconds": 30,
    "Clients": {
      "order-service": { "SharedSecret": "orders-base64-secret" }
    },
    "Targets": {
      "order-service": {
        "BaseUrl": "https://orders.example.com",
        "SharedSecret": "orders-base64-secret"
      }
    }
  }
}
builder.Services.AddHardenHmac(builder.Configuration.GetSection("HardenHmac"));

Documentation

Full documentation, canonical string specification, and cross-language compatibility details: github.com/HardenLabs/HardenHMAC

License

Apache License 2.0

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on HardenLabs.Hmac:

Package Downloads
HardenLabs.Hmac.AspNetCore

ASP.NET Core middleware and HttpClient handler for HardenHMAC request signing.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 157 4/5/2026
1.0.1 139 4/4/2026
1.0.0 144 4/4/2026
0.1.4 137 4/3/2026
0.1.4-rc2 129 4/3/2026
0.1.4-rc1 128 4/3/2026
0.1.3 134 4/1/2026
0.1.2 126 4/1/2026
0.1.1 128 4/1/2026
0.1.0 135 4/1/2026