Wiaoj.Identifiers.Security 0.1.0-alpha.6

This is a prerelease version of Wiaoj.Identifiers.Security.
dotnet add package Wiaoj.Identifiers.Security --version 0.1.0-alpha.6
                    
NuGet\Install-Package Wiaoj.Identifiers.Security -Version 0.1.0-alpha.6
                    
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="Wiaoj.Identifiers.Security" Version="0.1.0-alpha.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Wiaoj.Identifiers.Security" Version="0.1.0-alpha.6" />
                    
Directory.Packages.props
<PackageReference Include="Wiaoj.Identifiers.Security" />
                    
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 Wiaoj.Identifiers.Security --version 0.1.0-alpha.6
                    
#r "nuget: Wiaoj.Identifiers.Security, 0.1.0-alpha.6"
                    
#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 Wiaoj.Identifiers.Security@0.1.0-alpha.6
                    
#: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=Wiaoj.Identifiers.Security&version=0.1.0-alpha.6&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Wiaoj.Identifiers.Security&version=0.1.0-alpha.6&prerelease
                    
Install as a Cake Tool

Wiaoj.Identifiers.Security

Encrypts Wiaoj.Identifiers under a Wiaoj.Security key ring, so identifier keys are stored, wrapped by the master key and rotated like the rest of your secrets.

Installation

dotnet add package Wiaoj.Identifiers.Security

Usage

public sealed class IdentifierContext : ISecretContext;

builder.Services.AddWiaojSecurity()
    .AddEnvironmentMasterKey()
    .AddEntityFrameworkKeyStore<AppDbContext>()
    .AddManagedProtector<IdentifierContext>();

builder.Services.AddIdentifiers().UseKeyRingCodec<IdentifierContext>();

Generated identifiers then work as usual (id.ToString(), UserId.Parse(text), JSON, binding), with their text written as usr_ + key version + 22 characters.

Compared with UseAesCodec()

UseAesCodec() UseKeyRingCodec<TContext>()
Key One base64 key in configuration The domain's key ring, stored and wrapped by the master key
Rotation Changing the key breaks every issued identifier New identifiers use the new version, and earlier ones still parse
Construction AES-128 block with an HMAC tag The same, keyed per version by a subkey

How it works

  • Per-version key: each key version gets an AesIdCodec, keyed by a 32-byte subkey derived with ISubkeyDeriver<TContext>.DeriveSubkey(version, "wiaoj.identifiers", …). The ring's keys are never exposed. The subkey is derived once per version and cached.
  • Writing: uses CurrentKeyVersion.
  • Reading: looks at the identifier's version character and decodes with every version in KeyVersions that has that character. The tag check refuses a version that didn't write the identifier.
  • Version character: the base62 digit of the version modulo 62: 19, AZ, az, then 0. After version 61 the characters repeat; versions sharing a character are both tried, so reading still works.

Rotation

AddManagedProtector<TContext>() reloads the key ring on rotation, and the codec follows the reload. No restart is needed.

await keyRotationService.ForceRotateAsync();   // KeyRotationService<IdentifierContext>

id.ToString();              // now "usr_2…"
UserId.Parse(oldText);      // an identifier written as "usr_1…" still parses

Keep retired versions in the ring for as long as their identifiers are in circulation: in URLs, in other systems' databases, in emails. An identifier whose version is removed from the ring can no longer be read.

This is different from secrets encrypted with ISecretProtector, which IDataRotator re-encrypts: identifiers are held by clients, so they can't be rewritten. What you store is Value, the Snowflake (see Wiaoj.Identifiers.EntityFrameworkCore), so rotation never touches your database.

Startup

Using UseKeyRingCodec<TContext>() without AddManagedProtector<TContext>() fails when the host starts, because there is no ISubkeyDeriver<TContext>. Keys are loaded lazily, on the first identifier written or read, and AddManagedProtector pre-warms them while the host starts.

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
0.1.0-alpha.6 35 9/16/2026
0.1.0-alpha.5 39 9/16/2026
0.1.0-alpha.4 36 9/16/2026