note 98178 deleted from mcrypt.examples by visualmind
| From: | visualmind@php.net | Date: | Mon, 31 May 2010 12:13:12 +0000 |
| Subject: | note 98178 deleted from mcrypt.examples by visualmind | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-169741@lists.php.net to get a copy of this message | ||
Note Submitter: moquist at majen dot net
----
Correction - the padding character count is 1-based instead of 0-based (duh). Here's the
corrected function:
function decrypt($password) {
$key = 'some key';
$iv = 'some iv';
$cipher = mcrypt_module_open(MCRYPT_TRIPLEDES,'','cbc','');
mcrypt_generic_init($cipher, $key, $iv);
$decrypted = mdecrypt_generic($cipher,$bytes);
mcrypt_generic_deinit($cipher);
for($i=0; $i < strlen($decrypted); $i++) {
if(ord($decrypted[$i]) <= 8) {
$decrypted = substr($decrypted, 0, $i);
break;
}
}
return $decrypted;
}