I am wondering are there any issues with the MCrypt library in PHP, because I am making an encryption/decryption test. In the same file I have a encryption and decryption, no functions no nothing. When I encrypt, everything is perfect, but when I start decrypting right after that, the output becomes garbage. I am sure that I am passing the same key and IV, I have even changed the algorithm (3DES and RIJNDEAL-128) in OFB and ECB. Everything is the same.
The versions of MCrypt of my concern are:
Version 2.5.8
API 20021217
PHP Version 5.4.6-1ubuntu1.1
Apache 2.2.22
OS: Ubuntu 12.10 x64Version: 2.5.8
API: 20021217
PHP Version 5.3.15
Apache 2.2.22
OS: CentOS x64 (HostGator Shared)Also the problem is not in the x64, because I have previously used ubuntu 12.04 on x86 Machine
Edit
$time = microtime();
$key_size = mcrypt_get_key_size(MCRYPT_RIJNDAEL_128);
$key = substr(md5($time),0,$key_size);
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = substr(sha1($time),0,$iv_size);
$secret = "14 SPROWSTON ROAD";
$crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $secret, MCRYPT_MODE_CBC);
print $crypt;
print "<br />";
echo mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $crypt, MCRYPT_MODE_CBC);
Output
14�’�V�>�CN ROAD
It turns out that the problem was at the side behind the computer.. It was my own coding error.