PostgreSQL (Npgsql) persistence provider for Feedemy.KeyManagement. Provides PostgreSQL storage for key metadata, versions, and audit logs with migrations support. Platform-independent alternative to SQL Server.
$ dotnet add package Feedemy.KeyManagement.Providers.NpgsqlEnterprise-grade key management library for .NET applications.
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
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();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();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;
}
}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"
}
]
}// 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");| 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 |
| 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 |
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 setupThis project is dual-licensed:
| 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
Copyright (c) 2025 Feedemy