SchrottID 3.1.0

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

SchrottID

<img alt="Nuget" src="https://img.shields.io/nuget/dt/SchrottID?logo=nuget&label=NuGet&link=https%3A%2F%2Fwww.nuget.org%2Fpackages%2FSchrottID%2F">

SchrottID is a library for generating short, non-consecutive and opaque IDs from unsigned integers. These can be used to obfuscate integer primary keys from your database and prevent enumeration of rows and leaking other confidential information (see German tank problem).

SchrottIDs can be used where UUIDs would be impractical and too long to remember.

// Choose a character set for your SchrottIDs
string alphabet = Alphabets.Base64;

// Generate a permutation for your alphabet
// The permutation is your "key" for encoding and decoding
// You cannot decode IDs correctly without this key
string permutation = SchrottIdUtil.GeneratePermutation(alphabet);

// Choose a minimum length for your SchrottIDs
int minimumLength = 3;

// Make sure to store the three parameters above

// Create a encoder/decoder
SchrottIdEncoder schrottId = new SchrottIdEncoder(alphabet, permutation, minimumLength);

// A primary key from your database
ulong primaryKey = 420;

// Encode primaryKey to a SchrottID that you can safely expose
string externalId = schrottId.Encode(primaryKey);
// externalId = 9TN

// Decode back into your internal ID
ulong decodedKey = schrottId.Decode(externalId);
// decodedKey = 420

Implementations in other languages should very similar APIs. IDs generated by the same major version of the library are always stable.


Creating a new implementation

Implementations in other languages are very welcome. Create a new folder for your implementation and submit a pull request. Use test/control.txt to verify your implementation. C# is the reference implementation.


This library is inspired by block-id and removes the dependency on a deterministic random number generator so implementations in other languages are easier. The libraries are not cross-compatible.

Disclaimer: I'm not a cryptographer and IDs generated by this library can possibly be reversed engineered. Use with caution.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.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
3.1.0 377 8/16/2023
3.0.1 235 8/16/2023
3.0.0 218 8/16/2023
2.0.0 247 8/13/2023
1.0.0 227 8/10/2023