EncryptedInt 1.0.0
dotnet add package EncryptedInt --version 1.0.0
NuGet\Install-Package EncryptedInt -Version 1.0.0
<PackageReference Include="EncryptedInt" Version="1.0.0" />
<PackageVersion Include="EncryptedInt" Version="1.0.0" />
<PackageReference Include="EncryptedInt" />
paket add EncryptedInt --version 1.0.0
#r "nuget: EncryptedInt, 1.0.0"
#:package EncryptedInt@1.0.0
#addin nuget:?package=EncryptedInt&version=1.0.0
#tool nuget:?package=EncryptedInt&version=1.0.0
๐ EncryptedId
A lightweight, fast, reversible ID obfuscation library for .NET.
EncryptedId allows you to safely expose IDs (integers) without revealing your real ID.
It converts integer IDs into short, encoded strings before sending them to the client and decodes them back into integers when received.
โจ Why Use EncryptedId?
This library is perfect for:
- API Responses: Safely exposing internal IDs in JSON.
- Preventing ID Enumeration: Stops attackers from scraping your data by simply changing the ID from
1to2to3. - Controlled Reversible Mapping: A consistent, two-way mapping between the integer and the encoded string.
๐ Installation
Install the package via the .NET CLI:
dotnet add package EncryptedId
Configuration
Configure the library once at application startup.
using EncryptedId.Configuration;
EncryptedConfig.Salt = builder.Configuration["EncryptedId:Salt"];
EncryptedConfig.Alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
EncryptedConfig.MinLength = 6; // optional padding
๐ Salt
- Must be secret
- Must be long and random
- Must never change once in production
Store it in
{
"EncryptedId": {
"Salt": "SuperSecret_Long_Random_Value_Here"
}
}
๐ API / ASP.NET Core Integration
Use in controller models:
public record UserDto(EncryptedId Id, string Name);
API response:
{
"id": "Xkd02p",
"name": "John Doe"
}
Controller receives decoded ID automatically.
๐ MVC & Model Binding
EncryptedId supports model binding through EncryptedIdTypeConverter.
Works automatically with:
GET /users/Ab39Fp
Controller:
[HttpGet("{id}")]
public IActionResult GetUser(EncryptedId id)
{
int internalId = id.Value;
...
}
๐งช Error Handling
If an invalid encoded ID is received:
- JSON converter throws
JsonException - TypeConverter throws
FormatException - Decode returns
null
This prevents:
- tampering
- invalid requests
- malformed IDs
- injection attacks
โ FAQ
Why not use GUIDs?
They're long, ugly, and user-unfriendly.
Why not use encryption instead?
Overkill. APIs rarely require cryptographic secrecy for primary keys.
Can someone reverse the encoding?
Not without:
- your salt
- your shuffled alphabet
- your internal algorithm
Which is realistically non-practical.
Can I rotate salt?
Not without invalidating previous encoded IDs.
| Product | Versions 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. |
-
net8.0
- Dapper (>= 2.1.35)
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 |
|---|