Jump to content

why is mcrypt stopping at 32 characters?


doa24uk

Recommended Posts

Why is this stopping decoding at 32 characters??  :facewall: :facewall:

 

Encryption part

 

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

// Secret key to encrypt/decrypt with
$key = 'something';


// String to encrypt
$message = "http://mysite.com/123456789564738752057521097530219750123750921375307953213125";


// EnCrypt string
$encrypted = mc_encrypt($message, $key);

 

Decryption Part

 

$encrypted2 = $_GET["passedvariable"];

// Secret key to encrypt/decrypt with
$key = 'something'; // 8-32 characters without spaces


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



// DeCrypt back
$decrypted = mc_decrypt($encrypted2, $key);

 

 

Am I using the wrong mcrypt algorigthm? If so which one supports up to 150 characters & how do I alter it in the above example??

 

Many thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/168411-why-is-mcrypt-stopping-at-32-characters/
Share on other sites

The problem is because you are passing the encoded value through a URL and it can contain characters that are not permitted in a url or it can contain characters that  look like they are already urlencoded characters. You need to use urlencode and htmlentities on the encoded value before you put it into the URL to insure that the URL is valid and that it does not contain any HTML characters that would break the HTML on the page.

Archived

This topic is now archived and is closed to further replies.

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