Feedemy.KeyManagement.Providers.Npgsql
3.1.0
dotnet add package Feedemy.KeyManagement.Providers.Npgsql --version 3.1.0
NuGet\Install-Package Feedemy.KeyManagement.Providers.Npgsql -Version 3.1.0
<PackageReference Include="Feedemy.KeyManagement.Providers.Npgsql" Version="3.1.0" />
<PackageVersion Include="Feedemy.KeyManagement.Providers.Npgsql" Version="3.1.0" />
<PackageReference Include="Feedemy.KeyManagement.Providers.Npgsql" />
paket add Feedemy.KeyManagement.Providers.Npgsql --version 3.1.0
#r "nuget: Feedemy.KeyManagement.Providers.Npgsql, 3.1.0"
#:package Feedemy.KeyManagement.Providers.Npgsql@3.1.0
#addin nuget:?package=Feedemy.KeyManagement.Providers.Npgsql&version=3.1.0
#tool nuget:?package=Feedemy.KeyManagement.Providers.Npgsql&version=3.1.0
Feedemy.KeyManagement
Enterprise-grade key management library for .NET applications.
Features
- Automatic Key Rotation - Background service with configurable intervals
- Versioned Encryption - Auto-decryption with version detection
- Asymmetric Keys - RSA (2048/3072/4096) and ECDSA (P-256/P-384/P-521)
- Multi-Platform Storage - Windows DPAPI, Linux Keyring, Azure Key Vault
- Distributed Caching - Redis with pub/sub invalidation
- Database Persistence - SQL Server, PostgreSQL, and SQLite
- Health Monitoring - ASP.NET Core health checks
- Fallback Storage - Multi-provider redundancy
- Audit Trail - Complete compliance logging
- Roslyn Analyzers - 48 compile-time security rules
Installation
dotnet add package Feedemy.KeyManagement
# Persistence (choose one)
dotnet add package Feedemy.KeyManagement.Providers.EntityFramework # SQL Server
dotnet add package Feedemy.KeyManagement.Providers.Npgsql # PostgreSQL
dotnet add package Feedemy.KeyManagement.Providers.Sqlite # SQLite (dev/testing)
# Optional
dotnet add package Feedemy.KeyManagement.Analyzers
Quick Start
Development Setup
using Feedemy.KeyManagement.Extensions;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddKeyManagement(options =>
{
options.EnableAutoRotation = true;
options.RotationCheckInterval = TimeSpan.FromHours(6);
options.DefaultRotationDays = 90;
});
var app = builder.Build();
app.Run();
Production Setup
builder.Services.AddKeyManagement(options =>
{
options.EnableAutoRotation = true;
options.RotationCheckInterval = TimeSpan.FromHours(6);
// Auto-initialization
options.Initialization.EnableAutoInitialization = true;
options.Initialization.ExternalKeysJsonPath = "keys.json";
})
.WithAzureKeyStorage("https://your-vault.vault.azure.net/")
.WithRedisCache("localhost:6379")
.WithSqlServerMetadata("Server=localhost;Database=KeyManagement;...");
builder.Services.AddHealthChecks()
.AddKeyManagementHealthCheck();
Basic Usage
public class MyService
{
private readonly IKeyManagementService _keyService;
private readonly IKeyManagementAdminService _adminService;
// Create a key
public async Task CreateKeyAsync()
{
await _adminService.CreateKeyAsync(new CreateKeyRequest
{
KeyName = "MyEncryptionKey",
AutoGenerate = true,
KeySize = 32,
RotationIntervalDays = 90,
CreatedBy = "Admin"
});
}
// Retrieve a key (cached - sub-millisecond)
public async Task<byte[]> GetKeyAsync()
{
return await _keyService.RetrieveKeyAsync("MyEncryptionKey");
}
// Check health
public async Task<KeyHealthStatus> GetHealthAsync()
{
var health = await _keyService.GetKeyHealthAsync("MyEncryptionKey");
return health.Status;
}
}
Key Initialization
Define keys in keys.json for auto-generation on first run:
{
"Keys": [
{
"KeyName": "EncryptionKey",
"KeyType": "Symmetric",
"RotationIntervalDays": 90,
"Category": "MasterKey"
},
{
"KeyName": "JwtSigningKey",
"KeyType": "RSA",
"KeySize": 2048,
"RotationIntervalDays": 180,
"Category": "Signing"
}
]
}
Asymmetric Keys
// Sign data
var signature = await _asymmetricOps.SignAsync(
"JwtSigningKey",
data,
HashAlgorithmName.SHA256);
// Verify signature
var isValid = await _asymmetricOps.VerifyAsync(
"JwtSigningKey",
data,
signature,
HashAlgorithmName.SHA256);
// Get public key for external use
var publicKeyPem = await _asymmetricOps.GetPublicKeyPemAsync("JwtSigningKey");
Performance
| Operation | Mean | Notes |
|---|---|---|
| RetrieveKey (cached) | < 1 μs | L1 cache hit |
| RetrieveKey (cache miss) | ~12 ms | Database + storage |
| Sign (RSA-2048) | ~1.2 ms | |
| Verify (RSA-2048) | ~0.15 ms | |
| Sign (ECDSA P-256) | ~0.35 ms | |
| Verify (ECDSA P-256) | ~0.12 ms |
Packages
| Package | Description |
|---|---|
Feedemy.KeyManagement |
Core library |
Feedemy.KeyManagement.Providers.EntityFramework |
SQL Server persistence |
Feedemy.KeyManagement.Providers.Npgsql |
PostgreSQL persistence |
Feedemy.KeyManagement.Providers.Sqlite |
SQLite persistence (dev/testing) |
Feedemy.KeyManagement.Analyzers |
Roslyn analyzers |
Documentation
Detailed documentation available in docs/partial/:
README_CORE.md- API referenceREADME_CONFIG.md- Configuration optionsREADME_STORAGE.md- Storage providersREADME_PERSISTENCE.md- Database setupREADME_CACHE.md- Caching architectureREADME_INIT.md- Initialization guideREADME_BACKGROUND.md- Background servicesREADME_EXTENSIONS.md- DI setup
License
This project is dual-licensed:
- MIT License - Free for all use cases including commercial
- Commercial License - For enterprise support, SLA, and priority features
| Use Case | License | Cost |
|---|---|---|
| Personal projects | MIT | Free |
| Open source projects | MIT | Free |
| Commercial products | MIT | Free |
| Enterprise support & SLA | Commercial | Paid |
Commercial inquiries: licensing@feedemy.com
Support
Copyright (c) 2025 Feedemy
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Feedemy.KeyManagement (>= 3.1.0)
- Microsoft.EntityFrameworkCore (>= 10.0.3)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.3)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v3.0.0 - Major version alignment with Feedemy.KeyManagement 3.0.0
BREAKING CHANGES:
- Requires Feedemy.KeyManagement 3.0.0+ (not backward compatible with 2.x core)
- IKeyMetadataRepository: new required members (ExistsIncludingInactiveAsync, GetByKeyNameAsync)
- OperationResult<T> is now immutable (init-only properties)
UPDATED:
- EF Core unified to 10.0.1
- Npgsql.EntityFrameworkCore.PostgreSQL 10.0.0
- Target framework: .NET 10.0
- All repository implementations comply with v3.0.0 interface contracts
- SQL injection fix in DatabaseMigrator (parameterized queries via NpgsqlParameter)
SECURITY:
- CRITICAL: Fixed SQL injection in PostgreSQL DatabaseMigrator — version/description parameters now use NpgsqlParameter instead of string interpolation
- Parameterized SQL queries throughout
- CryptographicOperations.ZeroMemory patterns in key material handling
COMPATIBILITY:
- Requires Feedemy.KeyManagement 3.0.0+
- .NET 10.0
- PostgreSQL 12+
- Npgsql.EntityFrameworkCore.PostgreSQL 10.0.0