primid
v1.0.5
Published
Transform your internal id's to obfuscated integers based hashes
Downloads
3
Maintainers
Readme
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
- Create a new
primid
instance using
var primid = require('primid');
var generator = primid(1580030173, 59260789, 1163945558);
- Generate a hash, in this example we want to obfruscate the value
15
let hash=generator.encode(15);
- Use the hash as output of your API or other system.
- Turn the hash back into a number. If the hash from the example above is used, then
id
is equal to15
.
let id=generator.decode(hash);