DKNet.EfCore.Encryption
10.1.21
See the version list below for details.
dotnet add package DKNet.EfCore.Encryption --version 10.1.21
NuGet\Install-Package DKNet.EfCore.Encryption -Version 10.1.21
<PackageReference Include="DKNet.EfCore.Encryption" Version="10.1.21" />
<PackageVersion Include="DKNet.EfCore.Encryption" Version="10.1.21" />
<PackageReference Include="DKNet.EfCore.Encryption" />
paket add DKNet.EfCore.Encryption --version 10.1.21
#r "nuget: DKNet.EfCore.Encryption, 10.1.21"
#:package DKNet.EfCore.Encryption@10.1.21
#addin nuget:?package=DKNet.EfCore.Encryption&version=10.1.21
#tool nuget:?package=DKNet.EfCore.Encryption&version=10.1.21
DKNet.EfCore.Encryption
Transparent, column-level encryption for EF Core string properties. Mark a property [Encrypted], register a key provider, and EF Core encrypts values with AES-GCM before they hit the database and decrypts them on read — application code always sees plaintext.
dotnet add package DKNet.EfCore.Encryption
Features
[Encrypted]attribute — opt-in marker for anystringproperty.AesGcmColumnEncryptionProvider— default AES-128/192/256-GCM implementation (random IV per value, authenticated encryption).IColumnEncryptionProvider— swappable encryption algorithm abstraction.IEncryptionKeyProvider— bring your own key source (config, env var, Key Vault, etc.), one key per entity type.ModelBuilder.UseColumnEncryption(...)— one call inOnModelCreatingwires up every[Encrypted]property automatically; rejects primary/foreign key columns.services.AddEfCoreEncryption<TKeyProvider>()— registers your key provider in DI.
Quick start
public sealed class AppEncryptionKeyProvider : IEncryptionKeyProvider
{
private readonly byte[] _key = Convert.FromBase64String(
Environment.GetEnvironmentVariable("APP_ENCRYPTION_KEY")!); // 16, 24, or 32 bytes
public byte[] GetKey(Type entityType) => _key;
}
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEfCoreEncryption<AppEncryptionKeyProvider>();
public class Customer
{
public int Id { get; set; }
[Encrypted]
public string? Ssn { get; set; }
}
public class AppDbContext(DbContextOptions<AppDbContext> options, IEncryptionKeyProvider keyProvider)
: DbContext(options)
{
public DbSet<Customer> Customers => Set<Customer>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.UseColumnEncryption(keyProvider);
}
}
Customisation reference
There is no options class and nothing is bound from appsettings.json — the customisation surface is the key
provider you write plus two wiring calls.
| Knob | Type | Default | Effect |
|---|---|---|---|
[Encrypted] |
property attribute | — | Opts a string property in. AttributeTargets.Property; nothing else is scanned. |
IEncryptionKeyProvider.GetKey(Type entityType) |
byte[] |
none — you implement it | The AES key for every [Encrypted] property on that entity type. Evaluated once per property, at model-build time. |
AesGcmColumnEncryptionProvider(byte[] key) |
byte[] |
required | Key material. Exactly 16, 24 or 32 bytes; anything else throws ArgumentException, null throws ArgumentNullException. |
IColumnEncryptionProvider |
interface | AesGcmColumnEncryptionProvider |
Implement it to swap the algorithm; ColumnEncryptionConverter takes any implementation. |
AddEfCoreEncryption<TKeyProvider>() |
IServiceCollection extension |
— | Registers TKeyProvider as the singleton IEncryptionKeyProvider, and only when one is not already registered. |
ModelBuilder.UseColumnEncryption(keyProvider) |
ModelBuilder extension |
— | Must be called from OnModelCreating. Without it [Encrypted] has no effect at all. |
Ciphertext layout is fixed: Base64 of a 12-byte random IV, a 16-byte GCM tag, and the ciphertext, in that order.
null and empty strings pass through unchanged. Marking a primary or foreign key [Encrypted] throws
InvalidOperationException while the model is being built. There is no key rotation, versioned ciphertext, or
per-property key support.
Full documentation, configuration notes, and gotchas (query limitations on encrypted columns, key rotation, ciphertext sizing): https://github.com/baoduy/DKNet/blob/main/docs/EfCore/DKNet.EfCore.Encryption.md
| 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
- Microsoft.EntityFrameworkCore (>= 10.0.11)
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 |
|---|---|---|
| 10.1.24 | 40 | 9/11/2026 |
| 10.1.23 | 40 | 9/11/2026 |
| 10.1.22 | 42 | 9/11/2026 |
| 10.1.21 | 47 | 9/11/2026 |
| 10.1.20 | 47 | 9/9/2026 |
| 10.1.19 | 102 | 9/3/2026 |
| 10.1.18 | 94 | 9/3/2026 |
| 10.1.17 | 98 | 9/3/2026 |
| 10.1.16 | 99 | 9/3/2026 |
| 10.1.15 | 96 | 9/1/2026 |
| 10.1.14 | 91 | 9/1/2026 |
| 10.1.13 | 92 | 8/31/2026 |
| 10.1.12 | 91 | 8/25/2026 |
| 10.1.11 | 102 | 8/24/2026 |
| 10.1.10 | 94 | 8/22/2026 |
| 10.1.9 | 97 | 8/22/2026 |
| 10.1.8 | 90 | 8/21/2026 |
| 10.1.7 | 97 | 8/21/2026 |
| 10.1.6 | 99 | 8/21/2026 |
| 10.1.5 | 92 | 8/20/2026 |