I have this PHP function (using PHP 5.3) that I use to decrypt files, it works fine, but now that I switched to Amazon EC2 (based on Amazon Linux Image 2012.3), it seems that the mcrypt installation is either corrupt. either not available at all.
Initial tests show that file decryption works with smaller files, but not on 20 MB + files (which is not a particularly large size).
I traced the problem to this line, which causes a 500 error (I do not receive mcrypt_module_open is undefined, only 500 server errors )
$td = mcrypt_module_open ('rijndael-128', '', 'cbc', '');
Which is strange, I checked /etc/php.ini, I donโt see mcrypt at all (assuming I'm looking at the correct php.ini / path, of course!)
PHP code / function:
function decrypt_file ($inputfile, $outputfile)
{
$key = FILE_KEY;
$buffersize = 16384;
$input = fopen ($inputfile, 'rb');
if (!$input)
return false;
$output = fopen ($outputfile, 'wb');
if (!$output)
return false;
$td = mcrypt_module_open ('rijndael-128', '', 'cbc', '');
$iv = fread ($input, 16);
$keyhash = substr (hash ('sha512', $iv . $key, true), 0, 32);
mcrypt_generic_init ($td, $keyhash, $iv);
while (!feof ($input))
{
$buffer = fread ($input, $buffersize);
$buffer = mdecrypt_generic ($td, $buffer);
if (feof ($input))
{
$padsize = ord ($buffer[strlen ($buffer) - 1]);
$buffer = substr ($buffer, 0, strlen ($buffer) - $padsize);
}
fwrite ($output, $buffer, strlen ($buffer));
}
fclose ($input);
fclose ($output);
mcrypt_generic_deinit ($td);
mcrypt_module_close ($td);
return true;
}
- , ? PHP 5.3 CodeIgniter 2.1 (, CodeIgniter)