Currently I have a mysql table that displays information about job opportunities. I have an auto incrementing primary key and I want to encode so it isn't easily recognizable.
So the key "1" would be converted into something short like "AE93DZ". So for URL purposes it isn't something like somesite.com/view/1
Primary Key Unique Id | Job Name
1 | Gardening at X
2 | Dishwasher at Y
3 | Etc
4 | Etc
The primary key needs to be able to be decoded back into it's original key so I can search the database, eg if the user were to click the post then it needs to pull up that job post.
I have tried using Base64 encoding the key.
public static function encode( $input )
{
$salt= "example_salt";
$encrypted_id = base64_encode($input . $salt);;
return $encrypted_id;
}
public static function decode( $raw )
{
$salt = "example_salt";
$decrypted_id_raw = base64_decode($raw);
$decrypted_id = preg_replace(sprintf('/%s/', $salt), '', $decrypted_id_raw);
return $decrypted_id;
}
The encryption returns something like
OE1ZX1SKJS3KSJNMg==
which is too long and contains "=" signs.