I made an encrypt/decrypt methods that base on this model
// encrypt:
base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key),
$string, MCRYPT_MODE_CBC, md5(md5($key))))
//decrypt:
rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key),
base64_decode($encrypted), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
it all works well inside the same page, so that
decrypt(encrypt ('hello',$key))
works well,
but when I send the link:
echo "http://link.here?data=".urlencode(encrypt(('hello',$key)));
on the other receiving page I:
decrypt(urldecode($_GET['data']),$key));
I get a mess.
I notice that there is something VERY weird happening to the decrypted message.
I encrpyt ’72’, then read it back and decrypt it.
I noticed something very weird was happening when I tested it with is_numeric()… It didn’t respond to either true nor false !! something weird was going on….
So I tested with strlen, and the result was… 4 !
I figured something somehow happened with the bytes, but I have NO idea what it may be.
I am trying to pass a number through an email body, and I am trying to make it work,
any help would be appreciated.
Try taking the
urldecodeout of the code on your receiving page.Unless you’ve got double-encoding going on somewhere (and there’s no sign of that in what you’ve posted), you don’t need (or want) to
urldecodestrings from$_GET. PHP does this for you.For “text-only” data,
urldecodingtoo many times can end up being harmless. However, in your specific case, where the underlying text is Base64, it’s very likely to be harmful, sinceurldecodeconverts+signs (which are one of the characters used in Base64) to spaces.