Skip to content

Transform your internal id's to obfuscated integers based hashes

License

Notifications You must be signed in to change notification settings

khwstolle/go-primid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PrimID for Go

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

For the original Primid project written in JavaScript, see the GitHub page.

Installation

go get github.com/kurt-stolle/go-primid

Methods

PrimID uses only three functions.

import (
    "github.com/kurt-stolle/go-primid"
)

// Main function, for this small example
func main(){
    // Get a new generator using desired settings (should be unique settings per application).
    // These should be prime numbers!
    var generator=primid.NewGenerator(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 example

  1. Create a new primid instance using
var generator = primid.NewGenerator(1580030173, 1163945558)
  1. Generate a hash, in this example we want to obfruscate the value 15
var 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.
var id=generator.Decode(hash);

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

Languages