#29755 [Opn->Bgs]: Functions mcrypt don't work OK?
| From: | derick@php.net | Date: | Thu, 19 Aug 2004 11:44:31 +0000 |
| Subject: | #29755 [Opn->Bgs]: Functions mcrypt don't work OK? | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-64927@lists.php.net to get a copy of this message | ||
ID: 29755
Updated by: derick@php.net
Reported By: asoft at asoft dot no-ip dot org
-Status: Open
+Status: Bogus
Bug Type: mcrypt related
Operating System: Windows XP
PHP Version: 5.0.1
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions.
Thank you for your interest in PHP.
Your code is wrong, you're recreating the IV for decryption.
Previous Comments:
------------------------------------------------------------------------
[2004-08-19 13:40:46] asoft at asoft dot no-ip dot org
Description:
------------
$a="hola";
$b=cry($a,'sdglmsdd');
$c=dcry($b,'sdglmsdd')
result: $c!=$a
Correct result: $c==$a
Code until now working in version 4 of php
The function cry work how before. Seem work OK.
The function dcry FAIL. Don't work how before.
Reproduce code:
---------------
function cry($input,$key)
{$input = str_replace("\n","",$input);
$input = str_replace("\t","",$input);
$input = str_replace("\r","",$input);
$key = substr(md5($key),0,24);
$td = mcrypt_module_open ('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td),
MCRYPT_RAND);
mcrypt_generic_init ($td, $key, $iv);
$encrypted_data = mcrypt_generic ($td, $input);
mcrypt_module_close ($td);
return trim(chop(base64_encode($encrypted_data)));}
function dcry($input,$key)
{$input = str_replace("\n","",$input);
$input = str_replace("\t","",$input);
$input = str_replace("\r","",$input);
$input = trim(chop(base64_decode($input)));
$td = mcrypt_module_open ('tripledes', '', 'ecb', '');
$key = substr(md5($key),0,24);
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
mcrypt_generic_init ($td, $key, $iv);
$decrypted_data = mdecrypt_generic ($td, $input);
mcrypt_module_close ($td);
return trim(chop($decrypted_data));}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29755&edit=1