DKNet.EfCore.Encryption
13.3.1
dotnet add package DKNet.EfCore.Encryption --version 13.3.1
NuGet\Install-Package DKNet.EfCore.Encryption -Version 13.3.1
<PackageReference Include="DKNet.EfCore.Encryption" Version="13.3.1" />
<PackageVersion Include="DKNet.EfCore.Encryption" Version="13.3.1" />
<PackageReference Include="DKNet.EfCore.Encryption" />
paket add DKNet.EfCore.Encryption --version 13.3.1
#r "nuget: DKNet.EfCore.Encryption, 13.3.1"
#:package DKNet.EfCore.Encryption@13.3.1
#addin nuget:?package=DKNet.EfCore.Encryption&version=13.3.1
#tool nuget:?package=DKNet.EfCore.Encryption&version=13.3.1
DKNet.EfCore.Encryption
Encrypt and decrypt EF Core string columns through value converters for .NET developers.
✨ Why use it?
- Keep selected database columns unreadable as plaintext while entities expose normal strings.
- Detect ciphertext tampering through AES-GCM authentication.
- Supply your own key source without adopting the Hooks pipeline.
🚀 Quick Start
Use a .NET 10 console project. Install the packages, then replace Program.cs with the example.
dotnet new console -f net10.0 -n EfCoreDemo
cd EfCoreDemo
dotnet add package DKNet.EfCore.Encryption
dotnet add package Microsoft.EntityFrameworkCore.Sqlite --version 10.0.12
using System.Security.Cryptography;
using DKNet.EfCore.Encryption;
using DKNet.EfCore.Encryption.Attributes;
using DKNet.EfCore.Encryption.Encryption;
using DKNet.EfCore.Encryption.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using var connection = new Microsoft.Data.Sqlite.SqliteConnection("Data Source=:memory:");
connection.Open();
var services = new ServiceCollection();
services.AddEfCoreEncryption<DemoKey>();
services.AddDbContext<DemoDb>(o => o.UseSqlite(connection));
using var provider = services.BuildServiceProvider();
using var scope = provider.CreateScope();
await using var db = scope.ServiceProvider.GetRequiredService<DemoDb>();
await db.Database.EnsureCreatedAsync();
db.Add(new Customer { Secret = "demo-value" });
await db.SaveChangesAsync();
db.ChangeTracker.Clear();
Console.WriteLine((await db.Customers.SingleAsync()).Secret); // demo-value
using var command = connection.CreateCommand();
command.CommandText = "SELECT Secret FROM Customers";
Console.WriteLine((string)command.ExecuteScalar()! != "demo-value"); // True
public sealed class DemoKey : IEncryptionKeyProvider
{
private readonly byte[] _key = RandomNumberGenerator.GetBytes(32);
public byte[] GetKey(Type entityType) => _key;
}
public sealed class DemoDb(DbContextOptions<DemoDb> options, IEncryptionKeyProvider keys) : DbContext(options)
{
public DbSet<Customer> Customers => Set<Customer>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.UseColumnEncryption(keys);
}
}
public sealed class Customer
{
public int Id { get; set; }
[Encrypted]
public string? Secret { get; set; }
}
Run with dotnet run.
⚠️ Upgrading from 13.3.0 or earlier
UseColumnEncryption now throws InvalidOperationException at model build when [Encrypted] sits on a complex-type member, a complex property or a mapped member that is not a string. Earlier releases skipped those marks and stored the values as plaintext. Remove the attribute, or move the field to an entity or owned type as a string property and encrypt its stored values outside EF Core first: see Gotchas & limits.
Documentation
| Guide | Read when |
|---|---|
| Package overview | Start with architecture and the end-to-end flow. |
| Encrypt mapped columns | Attach converters and understand ciphertext and query limits. |
| Supply encryption keys | Register stable keys and plan model and data changes. |
| Use a custom encryption provider | Apply an explicit converter for another algorithm. |
| 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.12)
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 |
|---|---|---|
| 13.3.1 | 87 | 10/26/2026 |
| 13.3.0 | 96 | 10/22/2026 |
| 13.2.8 | 87 | 10/22/2026 |
| 13.2.7 | 99 | 10/11/2026 |
| 13.2.6 | 94 | 10/10/2026 |
| 13.2.5 | 99 | 10/2/2026 |
| 13.2.4 | 100 | 10/1/2026 |
| 13.2.3 | 104 | 10/1/2026 |
| 13.2.2 | 93 | 10/1/2026 |
| 13.2.1 | 103 | 10/1/2026 |
| 13.2.0 | 96 | 10/1/2026 |
| 13.1.3 | 117 | 9/21/2026 |
| 13.1.2 | 103 | 9/18/2026 |
| 13.1.1 | 101 | 9/18/2026 |
| 13.1.0 | 102 | 9/18/2026 |
| 13.0.2 | 111 | 9/18/2026 |
| 13.0.1 | 101 | 9/18/2026 |
| 13.0.0 | 108 | 9/18/2026 |
| 12.0.0 | 104 | 9/17/2026 |
| 11.0.0 | 110 | 9/17/2026 |