php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29172 mdecrypt not working anymore
Submitted: 2004-07-15 01:47 UTC Modified: 2004-07-20 23:50 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: lars at larswolter dot de Assigned:
Status: Closed Package: mcrypt related
PHP Version: 5.0.0 OS: Windows
Private report: No CVE-ID: None
 [2004-07-15 01:47 UTC] lars at larswolter dot de
Description:
------------
Just changed from php4 to php5. Now mcrypt decryption does not work anymore. The function returns the encrypted data instead of the decrypted.
The testcode is the example from the mdecrypt_generic function documentation.

using php.ini-recommended and only changed the following
display_errors = On
display_startup_errors = On
extensions_dir = ...

loaded extra modules:
gd2, mbstring, mcrypt, mysql, exif


Reproduce code:
---------------
<?php
   $key = 'this is a very long key...';
   $plain_text = 'very important data';
   $td = mcrypt_module_open('des', '', 'ecb','');
   $key = substr($key, 0, mcrypt_enc_get_key_size($td));
   $iv_size = mcrypt_enc_get_iv_size($td);
   $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
   if (mcrypt_generic_init($td, $key, $iv) != -1) {
	$c_t = mcrypt_generic($td, $plain_text);
	mcrypt_generic_deinit($td);
	mcrypt_generic_init($td, $key, $iv);
	$p_t = mdecrypt_generic($td, $c_t);
	mcrypt_generic_deinit($td);
	mcrypt_module_close($td);
	}
if (strncmp($p_t, $plain_text, strlen($plain_text)) == 0)
    echo "ok";
else
    echo "error";
?>

Expected result:
----------------
the result should be: ok

Actual result:
--------------
the result is: error

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-15 11:44 UTC] derick@php.net
Works fine for me on Linux, I saw this bug before and then it was a Windows issue too. I don't have a development setup for Windows here so I can't really help to track down this problem.
 [2004-07-16 12:52 UTC] taomyn at myway dot com
Have had no problems here under Windows Server 2003. My test code that I used when a previous 4.x upgrade "fixed" a feature but broke my code, still works fine:

<?
function encrypt_pwd($string) {
	srand((double) microtime() * 1000000);
	$key = md5("bubbles");

	$td = mcrypt_module_open('des', '','cfb', '');
	$key = substr($key, 0, mcrypt_enc_get_key_size($td));
	$iv_size = mcrypt_enc_get_iv_size($td);
	$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);

	mcrypt_generic_init($td, $key, $iv);
	$c_t = mcrypt_generic($td, $string);
	mcrypt_generic_deinit($td);
	mcrypt_module_close($td);
	$c_t = $iv . $c_t;
	return $c_t;
}

function decrypt_pwd($string) {
	$key = md5("bubbles");
	$td = mcrypt_module_open('des', '','cfb', '');
	$key = substr($key, 0, mcrypt_enc_get_key_size($td));
	$iv_size = mcrypt_enc_get_iv_size($td);
	$iv = substr($string, 0 ,$iv_size);
	$string = substr($string, $iv_size);

	mcrypt_generic_init($td, $key, $iv);

	$c_t = mdecrypt_generic($td, $string);
	mcrypt_generic_deinit($td);
	mcrypt_module_close($td);
	return $c_t;
}

$password = "muppet";

print "===".$password."===\n";
$password = encrypt_pwd($password);
print "===".$password."===\n";
$password = decrypt_pwd($password);
print "===".$password."===\n";

?>

Try this code and see what happens on your system.

I found the examples on the site at times a bit misleading (or I was having a bad day), but one of the kind developers here showed me my error and the code above is what I now use,

Taomyn
 [2004-07-16 12:56 UTC] taomyn at myway dot com
Sorry, forgot to mention, I get "ok" with your code.

Another thought, did you make sure to get the latest libmcrypt.dll when you upgraded? Mine is dated from 7 April, 2004 which I got from the link within the PHP site. To make sure of a clean upgrade I started with fresh clean folder and used the new PHP.INI from which I modified by taking values out of the v4 one (so I lost any deprecated stuff).
 [2004-07-20 23:50 UTC] lars at larswolter dot de
The new libmcrypt.dll fixed the problem

Thanks
Lars
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 19:01:29 2024 UTC