note 61047 deleted from function.mcrypt-cfb by danbrown
| From: | danbrown@php.net | Date: | Fri, 21 Aug 2009 13:30:28 +0000 |
| Subject: | note 61047 deleted from function.mcrypt-cfb by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-159737@lists.php.net to get a copy of this message | ||
Note Submitter: GloomM
----
Hi,
After some debugging of the script I found that the missing characters are due to the trim and chop
used in the script for some reason.
If you put it like so, you always get a perfect encryption/decryption:
function encrypt($key, $plain_text) {
$plain_text = trim($plain_text);
$iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_CAST_256,MCRYPT_MODE_CFB));
$c_t = mcrypt_cfb (MCRYPT_CAST_256, $key, $plain_text, MCRYPT_ENCRYPT, $iv);
return base64_encode($c_t);
}
function decrypt($key, $c_t) {
$c_t = base64_decode($c_t);
$iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_CAST_256,MCRYPT_MODE_CFB));
$p_t = mcrypt_cfb (MCRYPT_CAST_256, $key, $c_t, MCRYPT_DECRYPT, $iv);
return trim($p_t);
}
GloomM