doa24uk Posted August 1, 2009 Share Posted August 1, 2009 Hi guys, I need a very simply encryption algorithm, it will be used to encrypt (effectively hide) the actual URLs basically turning http://none.com into something like this f2kj932fj923fff so my URL (and hence what the user gets to see is the following) http://mysite.com/?myvar=f2kj932fj923fff Instead of this --> http://mysite.com?myvar=http://none.com I must be able to decode this string back to it's plain text with a seperate script though.... Quote Link to comment https://forums.phpfreaks.com/topic/168406-need-very-simple-encryption-for-urls/ Share on other sites More sharing options...
gevans Posted August 1, 2009 Share Posted August 1, 2009 You could take a look at mcrypt http://uk3.php.net/manual/en/book.mcrypt.php Quote Link to comment https://forums.phpfreaks.com/topic/168406-need-very-simple-encryption-for-urls/#findComment-888344 Share on other sites More sharing options...
doa24uk Posted August 1, 2009 Author Share Posted August 1, 2009 Sorry, I should have mentioned that I've tried several mcrypt algo's but my urls seem to be too long - they always cut off / stop decrypting at 32 characters. // Encrypt Function function mc_encrypt($encrypt, $mc_key) { $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND); $passcrypt = trim(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $mc_key, trim($encrypt), MCRYPT_MODE_ECB, $iv)); $encode = base64_encode($passcrypt); return $encode; } // Decrypt Function function mc_decrypt($decrypt, $mc_key) { $decoded = base64_decode($decrypt); $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND); $decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $mc_key, trim($decoded), MCRYPT_MODE_ECB, $iv)); return $decrypted; } $key = 'something'; $message = 'http://mysite.com/4329358521903853209358305219835210352185321095900-making-this-long-to-test-length'; $encrypted = mc_encrypt($message, $key); $decrypted = mc_decrypt($encrypted, $key); echo "Encrypted = " . $encrypted . "<br /><br />"; echo "Original message for reference = . $message .<br /><br />"; echo "Decrypted = " . $decrypted . "<br /><br />"; Quote Link to comment https://forums.phpfreaks.com/topic/168406-need-very-simple-encryption-for-urls/#findComment-888346 Share on other sites More sharing options...
gevans Posted August 1, 2009 Share Posted August 1, 2009 I guess you could take something really simple, like the character and its index position in the variable, substitute it from another array... easily reversable Quote Link to comment https://forums.phpfreaks.com/topic/168406-need-very-simple-encryption-for-urls/#findComment-888352 Share on other sites More sharing options...
gevans Posted August 1, 2009 Share Posted August 1, 2009 Or you could use something like base64_encode() http://us3.php.net/manual/en/function.base64-encode.php example <?php echo $foo = 'http://www.google.co.uk'; echo '<br /><br />'; echo base64_encode($foo); Quote Link to comment https://forums.phpfreaks.com/topic/168406-need-very-simple-encryption-for-urls/#findComment-888360 Share on other sites More sharing options...
Daniel0 Posted August 1, 2009 Share Posted August 1, 2009 You could also implement a simple shifting like the XOR cipher. Quote Link to comment https://forums.phpfreaks.com/topic/168406-need-very-simple-encryption-for-urls/#findComment-888383 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.