Reputation:
I was searching for a way to obfuscate the IDs that are show to the end user. But with a static number of digits Like the md5() function
, with the ability of reversing back to the original ID.
e.x: 1 => N9VRD7QB4SG2
e.x: 999999999 => RC401BALV74W
Upvotes: 0
Views: 91
Reputation: 731
I guess the simplest solution is to use the first N chars from a hash of the original ID (plus a salt) and storing the association on a database table:
hash_id | original_id
You can choose a hashing algorithm following these advices: http://www.php.net/manual/en/faq.passwords.php
EDIT: as zerkms wrote, you want to add a UNIQUE index on the hash_id column in order to avoid colliding hashes.
Upvotes: 1
Reputation: 60017
id = oldid ^ 0xfedad1234;
Coded
now
oldid = id ^ 0xfedad1234;
Back to the original
No SQL involved
Upvotes: 3