Philiprehberger.Obfuscator 0.1.8

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

Philiprehberger.Obfuscator

CI NuGet Last updated

Reversible integer/long ID obfuscation for URL-safe, non-sequential public IDs.

Installation

dotnet add package Philiprehberger.Obfuscator

Usage

Basic Encode/Decode

using Philiprehberger.Obfuscator;

var obfuscator = new IdObfuscator(salt: "my-secret-salt");

var encoded = obfuscator.Encode(42);
// e.g. "xR3j"

long decoded = obfuscator.DecodeSingle(encoded);
// 42

Multi-Value Encoding

var encoded = obfuscator.Encode(1, 2, 3);
// e.g. "aBcXyZ"

long[] values = obfuscator.Decode(encoded);
// [1, 2, 3]

Custom Alphabet and Minimum Length

var obfuscator = new IdObfuscator(
    salt: "my-salt",
    alphabet: "abcdefghijklmnopqrstuvwxyz",
    minLength: 8);

var encoded = obfuscator.Encode(1);
// e.g. "bejklqrs" (at least 8 characters, lowercase only)

Safe Decoding

if (obfuscator.TryDecode("xR3j", out var values))
{
    // values contains the decoded longs
}

Using Options Record

var options = new ObfuscatorOptions(Salt: "my-salt", MinLength: 6);
var obfuscator = new IdObfuscator(options);

JSON Serialization

using System.Text.Json;

var obfuscator = new IdObfuscator(salt: "my-salt");
var converter = new ObfuscatedIdConverter(obfuscator);

var jsonOptions = new JsonSerializerOptions();
jsonOptions.Converters.Add(converter);

// Serializes long fields as obfuscated strings
var json = JsonSerializer.Serialize(new { Id = 42L }, jsonOptions);
// {"Id":"xR3j"}

// Deserializes obfuscated strings back to longs
var obj = JsonSerializer.Deserialize<MyDto>(json, jsonOptions);

API

IdObfuscator

Method Description
IdObfuscator(string salt, string? alphabet, int minLength) Create an obfuscator with the given salt, optional alphabet, and minimum encoded length
IdObfuscator(ObfuscatorOptions options) Create an obfuscator from an options record
Encode(long value) Encode a single value to an obfuscated string
Encode(params long[] values) Encode multiple values to a single obfuscated string
Decode(string encoded) Decode an obfuscated string to an array of longs
DecodeSingle(string encoded) Decode an obfuscated string containing exactly one value
TryDecode(string encoded, out long[]? values) Attempt to decode without throwing on failure

ObfuscatedIdConverter

Method Description
ObfuscatedIdConverter(IdObfuscator obfuscator) Create a JSON converter using the given obfuscator

ObfuscatorOptions

Property Description
Salt The salt for shuffling the alphabet
Alphabet Custom alphabet characters (default: a-z, A-Z, 0-9)
MinLength Minimum encoded string length (default: 0)

Development

dotnet build src/Philiprehberger.Obfuscator.csproj --configuration Release

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.
  • net8.0

    • No dependencies.

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.8 118 4/1/2026
0.1.7 106 3/27/2026
0.1.6 107 3/23/2026
0.1.5 109 3/23/2026
0.1.4 110 3/17/2026
0.1.3 118 3/16/2026
0.1.2 105 3/16/2026
0.1.1 112 3/16/2026