Cookie Encryption troubles
| From: | Drew Foehn | Date: | Mon, 26 Jun 2000 15:11:28 +0000 |
| Subject: | Cookie Encryption troubles | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-3127@lists.php.net to get a copy of this message | ||
If anyone can see something wrong with this function and the way I call
it, please tell me whats up.
I made this function to save me from specifying the key in about 6
different if blocks, plus it saves time
writing out mcrypt_blah blah blah. I look at it and can see nothing
wrong with it, although I don't get the
right result when I decode it. Its something to do with the setting of
the cookie.
function usrcryp($user, $cryp, &$err){
$key = "a very special key";
$err .= "function usrcryp(".$user." , ".$cryp.")<br>\n"; //This
is for
debugging purposes so I can see what is getting passed to it
$encuser = mcrypt_ecb(MCRYPT_TripleDES, $key, $user, $cryp);
$err .= $encuser."<br>\n"; // more debugging
return $encuser;
}
//To call it:
$usrname = usrcryp($name, "MCRYPT_ENCRYPT", $err)
I'm using the encrypted data to form cookies. Somehow the cookie vals
that are being returned aren't being decoded properly
If I use this to set the cookie:
setcookie("uname" , usrcryp($username, "MCRYPT_ENCRYPT", $err),
time()+3600 );
and this to decrypt it:
$usrname = usrcryp($uname, "MCRYPT_DECRYPT", $err);
echo "$usrname\n"; //returns garbage
I know whats being passed to it in the first place before I encode it is
right, I get that from echoing the err var.
but once I get the encrypted data back from the cookie and pass it to
usrcryp it doesn't return the right decoded
username.
I could really use some help because i've tried everything, I know the
encryption function works on regular data,
but cookies don't seem to encode properlly. Its really annoying me.
Thanks
Drew