note 61047 added to function.mcrypt-cfb
| From: | GloomM at osu1 dot php dot net | Date: | Tue, 24 Jan 2006 11:14:18 +0000 |
| Subject: | note 61047 added to function.mcrypt-cfb | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-102348@lists.php.net to get a copy of this message | ||
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
----
Server IP: 82.146.33.222
Probable Submitter: 81.245.163.187
----
Manual Page -- http://www.php.net/manual/en/function.mcrypt-cfb.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61047
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61047&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61047&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61047&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61047&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61047&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61047&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61047&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61047&report=yes
Search -- http://master.php.net/manage/user-notes.php