Jump to content

Recommended Posts

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....

 

 

Link to comment
https://forums.phpfreaks.com/topic/168406-need-very-simple-encryption-for-urls/
Share on other sites

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 />";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.