I'm passing several several variables as an encrypted comma delimited string through the URL (coming from clickable links on an email), however I am having very inconsistent results when decrypting these strings. The most benign issue is that the values have invisible control chars that I have to trim, however some of the values are screwing up halfway through the decryption.
For example: I encrypt the string "ALC1000gk,10", and it decrypts as "ALC1000g=L¢î"
The code I'm using looks like this:
Code: Select all
$key = "Hey this key rocks!";
function cryptUrl($cryptToken, $cryptEdition, $key)
{
$cryptString = $cryptToken . ',' . $cryptEdition;
return (urlencode(mcrypt_ecb(MCRYPT_3DES, $key, $cryptString, MCRYPT_ENCRYPT)));
}
$urltok = cryptUrl("ALC1000gk","10", $key);
Code: Select all
function decryptUrl($cryptedString, $key)
{
return (mcrypt_decrypt(MCRYPT_3DES, $key, urldecode($cryptedString), "ecb"));
}
$pieces = explode(",", decryptUrl($tracking, $key));
$tmpToken = (filter_var($pieces[0],FILTER_SANITIZE_STRING));
$edition = (filter_var($pieces[1],FILTER_SANITIZE_STRING));
Thanks everyone!