Created
November 23, 2015 23:59
-
-
Save nilportugues/7617a83ab86ade36214f to your computer and use it in GitHub Desktop.
id-offuscation concept.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'vendor/autoload.php'; | |
//This hash must be a constant (user defined) | |
$tiny = new \ZackKitzmiller\Tiny('abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ5SX0TEjkR1mLOw8Gvq2VyJxIFhgCAYidrclDWaM3so9bfzZpuUenKtP74QNH6B'); | |
$firstletterSeparator = 'h'; | |
$lastletterSeparator = 'h'; | |
echo 'Original: '; | |
echo $id = 3; | |
echo PHP_EOL; | |
echo PHP_EOL; | |
echo 'Encoded LV1: '; | |
echo $id = $tiny->to($id); | |
echo PHP_EOL; | |
echo PHP_EOL; | |
echo 'Encoded LV2 (will be made public): '; | |
echo $encoded = md5("Blog").$firstletterSeparator.$id.$lastletterSeparator.md5("Post"); | |
echo PHP_EOL; | |
echo PHP_EOL; | |
echo '----------------------------------------------'.PHP_EOL; | |
echo 'Given public id, '.$encoded.', decode'; | |
echo PHP_EOL; | |
echo '----------------------------------------------'.PHP_EOL; | |
echo 'Decoded LV2: '; | |
echo $encoded = ($encoded); | |
echo PHP_EOL; | |
echo $encoded = ltrim($encoded, md5("Blog")); | |
echo PHP_EOL; | |
echo $encoded = rtrim($encoded, md5("Post")); | |
echo PHP_EOL; | |
echo $encoded = ltrim($encoded, $firstletterSeparator); | |
echo PHP_EOL | |
echo $encoded = rtrim($encoded, $lastletterSeparator); | |
echo PHP_EOL; | |
echo PHP_EOL; | |
echo 'Decoded LV1: '; | |
echo $encoded = $tiny->from($encoded); | |
echo PHP_EOL; | |
echo PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can be hardenned by adding and substracting a number too.
Eg: $id=1, lets encode by adding 1+512 and in decode do 513-512 = 1
Adds an additional level, makes hard to guess and it's computationally cheap.