EncryptedInt 1.0.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package EncryptedInt --version 1.0.0
                    
NuGet\Install-Package EncryptedInt -Version 1.0.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="EncryptedInt" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EncryptedInt" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="EncryptedInt" />
                    
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 EncryptedInt --version 1.0.0
                    
#r "nuget: EncryptedInt, 1.0.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 EncryptedInt@1.0.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=EncryptedInt&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=EncryptedInt&version=1.0.0
                    
Install as a Cake Tool

๐Ÿ” 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 1 to 2 to 3.
  • 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 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.

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