Skip to content

khwstolle/node-primid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PrimID

Transform your internal id's to obfuscated integers based hashes. This has the advantage that is is incredibly fast compared to other methods.

PrimID is written in pure javascript.

Installation

npm install primid

Methods

PrimID uses only three functions.

var primid=require("primid");
// Get a new generator using desired settings (should be unique settings per application).
// These should be prime numbers!
var generator=primid(prime,inverse[,xor]);

// Encode a number, get a integer based hash
var hash=generator.encode(some_number);

// Decode a hash, get back a number
var number=generator.decode(hash);

Numbers

You need to pick your own prime numbers unique to your application. For suggestions, look at this list.

Usage

  1. Create a new primid instance using
var primid = require('primid');
var generator = primid(1580030173, 59260789, 1163945558);
  1. Generate a hash, in this example we want to obfruscate the value 15
let hash=generator.encode(15);
  1. Use the hash as output of your API or other system.
  2. Turn the hash back into a number. If the hash from the example above is used, then id is equal to 15.
let id=generator.decode(hash);

Other implementations

There exist also the following implementations of this principle:

About

Transform your internal id's to obfuscated integers based hashes

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published