Naravel.Encryption
0.2.0
dotnet add package Naravel.Encryption --version 0.2.0
NuGet\Install-Package Naravel.Encryption -Version 0.2.0
<PackageReference Include="Naravel.Encryption" Version="0.2.0" />
<PackageVersion Include="Naravel.Encryption" Version="0.2.0" />
<PackageReference Include="Naravel.Encryption" />
paket add Naravel.Encryption --version 0.2.0
#r "nuget: Naravel.Encryption, 0.2.0"
#:package Naravel.Encryption@0.2.0
#addin nuget:?package=Naravel.Encryption&version=0.2.0
#tool nuget:?package=Naravel.Encryption&version=0.2.0
Naravel.Encryption
A thin Encrypt/Decrypt facade over ASP.NET Core Data Protection. No custom cryptography: keys, rotation and persistence stay in Data Protection.
| Fact | Detail |
|---|---|
| Install | dotnet add package Naravel.Encryption |
| Targets | .NET 10 |
| Needs | ASP.NET Core Data Protection (Microsoft.AspNetCore.DataProtection) and no other Naravel package |
What you get
- Strings and typed values.
Encryptreturns URL-safe text, andEncrypt<T>carries any JSON-serializable value. - No custom cryptography. Every key and every byte of protection belongs to ASP.NET Core Data Protection.
- Purposes.
ForPurpose("name")keeps the payloads of different uses apart. - Safe on bad input.
TryDecryptreturnsfalsewhereDecryptwould throwDecryptException. - The key ring stays yours. Persist it where every instance can read it; the notes under the example say why.
Quick start
using Naravel.Encryption;
builder.Services.AddNaravelEncryption(); // adds ASP.NET Core Data Protection only if the application has not registered it
app.MapGet("/demo", (IEncrypter encrypter) =>
{
var payload = encrypter.Encrypt("reset:42");
return encrypter.TryDecrypt(payload, out var value) ? value : "unreadable"; // "reset:42"
});
Decrypt throws DecryptException for a payload that was changed, was encrypted for another purpose or whose key is no longer in the key ring; TryDecrypt returns false in those cases instead. Encrypt<T> and Decrypt<T> use reflection, so a trimmed or Native AOT application passes a JsonTypeInfo<T>.
A payload can be read only by an application that uses the same key ring and the same Data Protection application name. With more than one instance, or when old payloads must survive a restart, persist the key ring in a place every instance can read. That is ASP.NET Core Data Protection configuration, not part of this package.
Related packages
| Package | Adds |
|---|---|
Naravel.Queue.Encryption |
Optional: stores the payload of selected queue jobs encrypted |
Learn more
- Encryption: English guide
- Changelog · Source and issues · MIT license
Part of Naravel: Laravel's names, .NET's type system. All Naravel packages share one version.
| 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.AspNetCore.DataProtection (>= 10.0.14)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Naravel.Encryption:
| Package | Downloads |
|---|---|
|
Naravel.Queue.Encryption
Optional Naravel.Queue adapter that encrypts the payload of jobs marked IShouldBeEncrypted with ASP.NET Core Data Protection. Unmarked jobs keep the existing wire format. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Release notes: https://github.com/km-arc/Naravel/releases/tag/v0.2.0 - full history: https://github.com/km-arc/Naravel/blob/main/CHANGELOG.md