ASP.NET Core で UUIDv7 のタイムスタンプ部を UUIDv47 アルゴリズムでマスクし、可逆的に変換するライブラリ
$ dotnet add package MaskedUUID.AspNetCoreA library for ASP.NET Core that masks the timestamp portion of UUIDv7 using the UUIDv47 algorithm with reversible transformation.
This library uses UUIDv47Sharp (C# implementation) to reversibly mask GUIDs.
UUIDv47 is a reversible encoding format that hides the timestamp portion of UUIDv7.
IMaskedUUIDKeyProvider (flexible support for different keys per tenant, etc.)UUIDv7 contains a 48-bit timestamp at the beginning, which means exposing it directly reveals the resource creation timestamp.
This poses the following information leakage risks:
This library automatically performs UUIDv7 ↔ UUIDv47 conversion at the following timing:
MaskedGuid type properties are converted to UUIDv47 when output to JSON/items/{id} with automatic restorationMaskedGuid type properties in Hub send/receiveMaskedGuid is masked (encoded/decoded) only during JSON input/output.MaskedGuid.ToString() returns the raw Guid string (not the masked string).MaskedGuid uses IMaskedUUIDService for masking during JSON conversion.Guid.Empty (empty GUID) becomes null in JSON output.null / "" (empty string) in JSON input is treated as Guid.Empty.MaskedGuid resolves IMaskedUUIDService from HttpContext.MaskedGuid outside HTTP requests (background processing, non-Web environments) will throw an exception.MaskedGuid / MaskedGuid? types.[MaskedUUID] attribute is not used (no attribute-based processing).MaskedGuid? is treated as null when the decode result is Guid.Empty.MaskedGuid remains as Guid.Empty when the decode result is Guid.Empty.
Guid.Empty is output as null and treated as Guid.Empty when read.IMaskedUUIDKeyProviderIMaskedUUIDServiceAddMaskedUUID() and AddMaskedUUIDModelBinder()See samples/MaskedUUID.Sample for samples.
// Register KeyProvider (Singleton recommended, Scoped also acceptable)
builder.Services.AddSingleton<IMaskedUUIDKeyProvider, MyKeyProvider>();
// Add MaskedUUID support
builder.Services.AddMaskedUUID();
// Add ModelBinder (for URL/query parameters)
mvcBuilder.AddMaskedUUIDModelBinder();
// Or all at once
mvcBuilder.AddMaskedUUIDControllers();
Use the AddMaskedUUID() extension method for SignalR support.
// Register KeyProvider
builder.Services.AddSingleton<IMaskedUUIDKeyProvider, MyKeyProvider>();
// Add MaskedUUID support to SignalR
builder.Services.AddSignalR().AddMaskedUUID();
SignalR converters resolve services in the following priority order:
This ensures correct operation whether KeyProvider/Service is Singleton / Scoped / Transient.
// Use reference keys for development/testing (do not use in production)
builder.Services.AddSignalR().AddMaskedUUIDWithReferenceKeys();
Supports .NET 10+ and .NET 9.
// Add OpenAPI schema transformer
builder.Services.AddOpenApi(options => options.AddMaskedGuidSchemaTransformer());
Automatically handles JsonSchemaType enum in .NET 10+ and string-based type specification in .NET 9.