Check out hashids , which is designed to create unique YouTube-style hashes from your primary keys (or another set of unique numbers). This is not really a hash in the sense of MD5 and SHA-1, as it is intended for reversibility.
As an example, if you want to "hash" your only integer primary key, you can get relationships like
(PK: 1) <=> (hashid: 8dY0qQ)
This is sown from a secret value that you control, so users cannot determine the primary key that they really refer to. If your database is somewhat more active, say with a few shards and complex keys, you're still fine. hashids takes a list of integers as input:
(3, 171, 24) <=> (243j7Z)
As a developer, you are responsible for determining the minimum hash length. As you create more hashes, hashids can generate slightly longer hashes.
Hashes are guaranteed to be unique to this input (seed, minimum hash length and a list of integers for the hash):
no collisions . Created hashes must be unique.
There is support
- Javascript
- ruby
- Python
- Java
- Php
- Perl
- CoffeeScript
- Objective-c
- Go
- Lua
- Node.js
- .NET
Chris source share