Kent.Cryptography.Obfuscation 2.0.0

dotnet add package Kent.Cryptography.Obfuscation --version 2.0.0                
NuGet\Install-Package Kent.Cryptography.Obfuscation -Version 2.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="Kent.Cryptography.Obfuscation" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kent.Cryptography.Obfuscation --version 2.0.0                
#r "nuget: Kent.Cryptography.Obfuscation, 2.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.
// Install Kent.Cryptography.Obfuscation as a Cake Addin
#addin nuget:?package=Kent.Cryptography.Obfuscation&version=2.0.0

// Install Kent.Cryptography.Obfuscation as a Cake Tool
#tool nuget:?package=Kent.Cryptography.Obfuscation&version=2.0.0                

Cryptography.Obfuscation

Obfuscator is a C# library that converts a non-negative integer into 8-character string, generating a result similar to YouTube video id. Put it simply, this library converts a numeric id such as 127 to xVrAndNb and back.

Preface

Obfuscation is not designed to to replace your authentication layer, but simply to provide an additional security step. Ideally, your application should be able to authenticate request without, for example, masking/obfuscating id in the query string.

Install

Install-Package Kent.Cryptography.Obfuscation

Obfuscator 2.0

Obfuscator 2.0 uses a slightly different algorithm compared to version 1.0. New algorithm is introduced to achieve true constant mode across all .NET versions. Prior to version 2.0, constant mode will still achieve expected result as long as you don't change the target framework of your project. If you have been using version 1.0.1 and finds this limitation acceptable, it's safe not to upgrade.

Usage

Basic Example

Provides unique id <> string mapping which will not change unless Seed value is changed.

  var obfuscator = new Obfuscator();
  string obfuscatedID = obfuscator.Obfuscate(15);   // e.g. xVrAndNb
  
  // Reverse-process:
  int deobfuscatedID = obfusactor.Deobfuscate(obfuscatedID);  // 15

Randomized Mode

Generates randomized sequence which will cause the Obfuscate function to generate different values even when obfuscating the same id.

  var obfuscator = new Obfuscator();
  obfuscator.Strategy = ObfuscationStrategy.Randomized;
  
  // 'randomized' to generate different sequence for the same id.
  string obfuscatedID = obfuscator.Obfuscate(15);         // e.g. MzQgC4rL
  string secondObfuscatedID = obfuscator.Obfuscate(15);   // e.g. 4sucAs0D
  
  // Reverse-process:
  int deobfuscatedID = obfusactor.Deobfuscate(obfuscatedID);    // 15
  deobfuscatedID = obfusactor.Deobfuscate(secondObfuscatedID);  // 15

Seed Value

Seed value is the 'differentiator' that makes id <> string mapping unique to your application. It is highly recommended to set this value rather than depending on the default value set by the library (which is 113).

  var obfuscator = new Obfuscator();
  obfuscator.Seed = 167;
  string obfuscatedID = obfuscator.Obfuscate(15);

Note: Minimum seed value is 2 and it's recommended to set this value to varying digits (instead of something like 100), as this will be used in XOR operations. Some example of recommended seed values are 113, 167, 73, etc.

License

This project is licensed under the GNU Public License v3.0. Feel free to reuse for personal and commercial use.

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. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.2 is compatible.  netstandard1.3 was computed.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net35 is compatible.  net40 was computed.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  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 tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Windows Phone wpa81 was computed. 
Windows Store netcore451 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.

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
2.0.0 26,972 11/3/2017
1.0.1 3,937 5/7/2017
1.0.0 912 5/7/2017

Version 2.0 is a breaking change. Constant mode generated in previous version won't be generated in the same way in this version onwards. This is due to a recent discovery that GetHashCode doesn't guarantee the same result across .NET versions. This is now changed to GetStableHashCode implementation, which in turn helps Obfuscation to achieve true Constant mode, even when your project migrates to another .NET version.