note 101232 added to mcrypt.examples
| From: | ecrane57 at gmail dot com | Date: | Fri, 03 Dec 2010 22:12:35 +0000 |
| Subject: | note 101232 added to mcrypt.examples | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174600@lists.php.net to get a copy of this message | ||
jizzy @ Nowhere posted a routine to encrypt and decrypt just below. The decrypt pad-character
removing function has a problem. It starts to low (0) and ends to high. So changing the $i in the
for loop to start at 1 and end before $bit_check like below, fixes the padding range. I tested with
a 40 character clear text and removed one char at a time down to 1 and it worked.
function decrypt($encrypted_text,$key,$iv,$bit_check){
$cipher = mcrypt_module_open(MCRYPT_TRIPLEDES,'','cbc','');
mcrypt_generic_init($cipher, $key, $iv);
$decrypted = mdecrypt_generic($cipher,base64_decode($encrypted_text));
mcrypt_generic_deinit($cipher);
$last_char=substr($decrypted,-1);
for($i=1; $i < $bit_check; $i++){
if(chr($i)==$last_char){
$decrypted=substr($decrypted, 0, strlen($decrypted) - $i);
break;
}
}
return $decrypted;
}
----
Server IP: 208.69.120.55
Probable Submitter: 67.175.223.43
----
Manual Page -- http://www.php.net/manual/en/mcrypt.examples.php
Edit -- https://master.php.net/note/edit/101232
Del: integrated -- https://master.php.net/note/delete/101232/integrated
Del: useless -- https://master.php.net/note/delete/101232/useless
Del: bad code -- https://master.php.net/note/delete/101232/bad+code
Del: spam -- https://master.php.net/note/delete/101232/spam
Del: non-english -- https://master.php.net/note/delete/101232/non-english
Del: in docs -- https://master.php.net/note/delete/101232/in+docs
Del: other reasons-- https://master.php.net/note/delete/101232
Reject -- https://master.php.net/note/reject/101232
Search -- https://master.php.net/manage/user-notes.php