Hrithik.Security.ApiKeyManagement 1.0.0

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

πŸ” Hrithik.Security.ApiKeyManagement

Enterprise-grade API key generation, validation, revocation, expiration, and scope-based authorization for ASP.NET Core APIs.

Designed for fintech, banking, SaaS, and partner integrations, this library helps teams implement API keys correctly and securely β€” avoiding common pitfalls like plaintext storage and weak authorization.

✨ Features

πŸ”‘ Secure API key generation (cryptographically strong)

πŸ”’ Hashed API key storage (never stores plaintext keys)

🎯 Scope-based authorization per endpoint

⏱️ Key expiration support

🚫 Instant key revocation

πŸ” Zero-downtime key rotation workflows

βš™οΈ ASP.NET Core middleware + attributes

🧩 Pluggable storage (in-memory, EF Core, custom)

πŸš€ Installation dotnet add package Hrithik.Security.ApiKeyManagement

πŸ› οΈ Quick Start 1️⃣ Register Services using Hrithik.Security.ApiKeyManagement.Extensions; using Hrithik.Security.ApiKeyManagement.Stores;

builder.Services.AddApiKeyManagement(options β‡’ { options.HashingSecret = "your-secure-server-secret"; });

// Development / testing builder.Services.AddSingleton<IApiKeyStore, InMemoryApiKeyStore>();

2️⃣ Add Middleware (Order Matters) app.UseApiKeyManagement();

Place this before request signing, replay protection, or authorization middleware.

3️⃣ Protect Endpoints with Scopes using Hrithik.Security.ApiKeyManagement.Attributes;

app.MapPost("/transfer", [RequireApiKeyScope("payments:write")] (decimal amount) β‡’ { return Results.Ok("Transfer successful"); });

πŸ”‘ Generating API Keys using Hrithik.Security.ApiKeyManagement.Models;

var apiKey = apiKeyService.GenerateKey( name: "IBM Production", scopes: new[] { new ApiKeyScope("payments:read"), new ApiKeyScope("payments:write") }, expiresAt: DateTime.UtcNow.AddDays(30) );

⚠️ The raw API key is shown only once. Store it securely on the client side.

πŸ” How API Key Validation Works

Client sends X-API-KEY header

Server hashes the key

Hashed value is compared against stored hash

Key status, expiry, and scopes are enforced

Request proceeds only if valid

πŸ” Key Rotation (Zero Downtime)

This library supports safe key rotation workflows:

Generate a new API key

Keep the old key active temporarily

Distribute the new key to the client

Revoke or expire the old key

await apiKeyService.RevokeAsync(oldKeyId);

Rotation scheduling and client notification are intentionally left to the host application.

🧠 Design Philosophy

API keys represent integration identity, not end users

Keys are immutable and auditable

Security decisions are explicit and deterministic

No hidden behavior or silent credential changes

πŸ§ͺ Storage Options Store Use Case InMemoryApiKeyStore Local dev, tests, demos EF Core Store Production (coming next) Custom Store Redis, DynamoDB, Vault, etc. πŸ” Security Best Practices

Never store API keys in plaintext

Always rotate keys periodically

Use scopes instead of multiple APIs

Combine with request signing and replay protection for maximum security

πŸ“Œ Typical Use Cases

Fintech & payment APIs

Partner integrations (B2B)

Internal microservices

Secure public APIs

Banking & regulated systems

πŸ“„ License

MIT License

🀝 Contributing

Issues, discussions, and PRs are welcome. Security improvements and feedback are highly appreciated.

⭐ Final Note

This library focuses on doing one thing well: secure, correct, and maintainable API key management.

If you’re building serious APIs, this gives you a solid foundation.

πŸ“§ Contact

Author: Hrithik Email: hrithikkalra11@gmail.com

NuGet: Hrithik.Security.ReplayProtection

β˜• Support my work
If you find this package helpful, consider buying me a coffee ❀️
πŸ‘‰ Buy Me a Coffee

or

consider supporting its development: πŸ‘‰ https://github.com/sponsors/hrithikalra

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.

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
1.0.0 134 1/31/2026