I am trying to send encrypted data at a URL to another site (using file_get_contents("anotherUrl.php?hash=$encryptedString") . The problem is that sometimes encryption contains some special characters, for example +, and this causes decryption to fail.
Here are my encryption / decryption methods:
public function encrypt($string, $key) { return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key)))); } public function decrypt($encrypted, $key) { return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted), MCRYPT_MODE_CBC, md5(md5($key))), "\0"); }
Here is an example of an encrypted string that contains + , and I assume that this causes decryption to fail.
oWCrVPaS+5GbxcQFc0fulUk/zRAkDD60av4zlPiWskE=
Any ideas how I should solve this? I tried to make urlencode() and urldecode() on the hash, however this also urldecode() encryption. Is there a way to change the encryption algorithm to make it return only safe URL characters?
php base64 url-encoding encryption mcrypt
Click upvote
source share