Giter Site home page Giter Site logo

kent-id / obfuscation Goto Github PK

View Code? Open in Web Editor NEW
18.0 4.0 6.0 59 KB

Obfuscation / Integer Masking library to encrypt numeric id to short string, generating a similar result to YouTube video id.

C# 100.00%
c-sharp c-sharp-library obfuscation obfuscator cryptography integer-masking obfuscate

obfuscation's Introduction

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

nuget package link: https://www.nuget.org/packages/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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.