DKNet.Svc.Encryption 10.1.24

dotnet add package DKNet.Svc.Encryption --version 10.1.24
                    
NuGet\Install-Package DKNet.Svc.Encryption -Version 10.1.24
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DKNet.Svc.Encryption" Version="10.1.24" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DKNet.Svc.Encryption" Version="10.1.24" />
                    
Directory.Packages.props
<PackageReference Include="DKNet.Svc.Encryption" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DKNet.Svc.Encryption --version 10.1.24
                    
#r "nuget: DKNet.Svc.Encryption, 10.1.24"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DKNet.Svc.Encryption@10.1.24
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DKNet.Svc.Encryption&version=10.1.24
                    
Install as a Cake Addin
#tool nuget:?package=DKNet.Svc.Encryption&version=10.1.24
                    
Install as a Cake Tool

DKNet.Svc.Encryption

NuGet NuGet Downloads .NET License

Standalone, explicitly-invoked cryptography toolkit: AES-GCM encryption, RSA encrypt/sign, HMAC and SHA hashing, and Base64/Base64URL helpers, all operating on UTF-8 strings. For transparent EF Core column encryption instead, see DKNet.EfCore.Encryption — a different package.

Features

  • IAesGcmEncryption — authenticated AES-256-GCM encryption with optional associated data
  • IRsaEncryption — RSA encrypt/decrypt (OAEP-SHA256) and sign/verify (PKCS1-SHA256), including public-key-only instances
  • IHmacHashing / IShaHashing — HMAC-SHA256/512 and SHA-256/512 compute + constant-time verify
  • Base64StringExtensions — Base64 and Base64URL encode/decode helpers

Installation

dotnet add package DKNet.Svc.Encryption

Quick Start

using DKNet.Svc.Encryption;
using DKNet.Svc.Encryption.Ciphers;

builder.Services.AddEncryptionServices();                                       // HMAC + SHA hashing
builder.Services.AddAesGcmEncryption(builder.Configuration["Crypto:AesKey"]!);  // singleton IAesGcmEncryption

public sealed class SecretStore(IAesGcmEncryption aesGcm)
{
    public string Protect(string plainText) => aesGcm.EncryptString(plainText);
    public string Reveal(string cipherPackage) => aesGcm.DecryptString(cipherPackage);
}

Migration — namespace changes in this release

Root types were grouped into concern folders; the namespace of each moved type now ends with its folder name. This is an import-only source break: no type was renamed, removed, resignatured, or had its behaviour changed — update the using line and you're done.

Type Old namespace New namespace
IAesGcmEncryption/AesGcmEncryption, IRsaEncryption/RsaEncryption DKNet.Svc.Encryption DKNet.Svc.Encryption.Ciphers
IHmacHashing/HmacHashing, IShaHashing/ShaHashing DKNet.Svc.Encryption DKNet.Svc.Encryption.Hashing

EncryptionSetup (registration point) and Base64StringExtensions (the Base64/Base64URL encoding helpers) stay at DKNet.Svc.Encryption.

Configuration — registration and constructor surface

There is no options type and no IConfiguration binding path. Everything a caller can vary is an argument.

Registration Argument Registers Lifetime
AddEncryptionServices() IShaHashing, IHmacHashing Transient
AddAesGcmEncryption(base64Key) Base64 128/192/256-bit key IAesGcmEncryption Singleton
AddRsaEncryption(privateKeyBase64) Base64 PKCS#1 private key IRsaEncryption Singleton

All three are idempotent — a second call registers nothing, so the first call's key is the one the application uses. The two cipher methods throw ArgumentException for a null, empty, or whitespace key.

Constructor / factory Parameter Default Effect
new AesGcmEncryption(string? key = null) Base64 key, must not contain : null null generates a random 256-bit key; a supplied key must decode to 16, 24, or 32 bytes.
new RsaEncryption(int keySize = 2048) Key size in bits 2048 Generates a fresh key pair.
new RsaEncryption(string privateKeyBase64) PKCS#1 private key (required) Loads an existing pair; the public key is derived.
RsaEncryption.FromPublicKey(string publicKeyBase64) PKCS#1 public key (required) Public-only: Encrypt/Verify work, Decrypt/Sign throw InvalidOperationException.
Per-call switch Default Effect
IAesGcmEncryption.EncryptString/DecryptStringassociatedData null Extra bytes bound into the tag; a mismatch on decrypt throws CryptographicException.
IHmacHashing.ComputeSha*asBase64 true false returns upper-case hex.
IHmacHashing.VerifySha*signatureIsBase64 true Must match how the signature was produced; a mismatch returns false.
IShaHashing.ComputeSha*upperCase false true returns upper-case hex.
IShaHashing.VerifySha*ignoreCase true No effect — comparison runs on decoded bytes.

Fixed, non-configurable choices: AES-GCM uses a fresh 12-byte nonce and a 16-byte tag per call and packages the result as Base64 of base64(nonce):base64(tag):base64(cipher); RSA uses OAEP-SHA256 for encryption and SHA-256 with PKCS#1 v1.5 for signatures; keys are exported as raw PKCS#1 DER in Base64, not PEM; every Verify* compares with CryptographicOperations.FixedTimeEquals.

Documentation

Full feature reference, configuration, and gotchas: https://github.com/baoduy/DKNet/blob/main/docs/Services/DKNet.Svc.Encryption.md

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 44 9/11/2026
10.1.23 41 9/11/2026
10.1.22 40 9/11/2026
10.1.21 49 9/11/2026
10.1.20 48 9/9/2026
10.1.19 140 9/3/2026
10.1.18 83 9/3/2026
10.1.17 86 9/3/2026
10.1.16 97 9/3/2026
10.1.15 132 9/1/2026
10.1.14 81 9/1/2026
10.1.13 89 8/31/2026
10.1.12 92 8/25/2026
10.1.11 97 8/24/2026
10.1.10 91 8/22/2026
10.1.9 106 8/22/2026
10.1.8 89 8/21/2026
10.1.7 93 8/21/2026
10.1.6 91 8/21/2026
10.1.5 156 8/20/2026
Loading failed