I use simple_encrypt
to store some sensitive information in the cookie. When I try to decrypt it with simple_decrypt
, it doesn't give the same string. When I try to output that string after simple_decrypt
I get chars with symbols like �
. What's wrong?
$salt ='sososo222xxxXXsder3FVRE';
function simple_encrypt($text)
{
global $salt;
return mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $salt, $text, MCRYPT_MODE_ECB);
}
function simple_decrypt($text)
{
global $salt;
return mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $salt, $text, MCRYPT_MODE_ECB);
}
EDIT: I use setcookie("rt", simple_encrypt($a['rt']), time()+(3600 * 24 * 365));
to store cookie. I also put echo simple_encrypt($a['rt']);
before setcooking, and got the different value that it is in the cookie. That's just amazing...
Try this:
function simple_encrypt($text)
{
global $salt;
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $salt, $text, MCRYPT_MODE_ECB));
}
function simple_decrypt($text)
{
global $salt;
return base64_decode(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $salt, $text, MCRYPT_MODE_ECB));
}