The*_*ude 3 php encryption codeigniter
我有这个PHP函数(使用PHP 5.3),我用来解密文件,它曾经工作得很好,但现在我转移到Amazon EC2(基于Amazon Linux Image 2012.3),似乎mcrypt安装已损坏或根本不可用.
初步测试表明,文件解密可以在较小的文件上工作,但不能在20MB +文件上工作(不是特别大的文件).
我将问题跟踪到此行,这导致错误500(我没有得到mcrypt_module_open is undefined,只有500服务器错误)
$td = mcrypt_module_open ('rijndael-128', '', 'cbc', '');
Run Code Online (Sandbox Code Playgroud)
有点奇怪,我检查了/etc/php.ini,我根本看不到mcrypt(假设我正在查看正确的php.ini /路径!)
PHP代码/功能是:
function decrypt_file ($inputfile, $outputfile)
{
$key = FILE_KEY; // <-- assign private key
$buffersize = 16384;
// Open $inputfile for reading binary
$input = fopen ($inputfile, 'rb');
// Error opening $inputfile, return false
if (!$input)
return false;
// Open $outputfile for writing binary
$output = fopen ($outputfile, 'wb');
// Error opening $outputfile, return false
if (!$output)
return false;
// Open the cipher module
$td = mcrypt_module_open ('rijndael-128', '', 'cbc', '');
// Read the IV from $inputfile
$iv = fread ($input, 16);
// Compute the SHA512 of the IV (salt) and Key and use 32 bytes (256 bit) of the result as the encryption key
$keyhash = substr (hash ('sha512', $iv . $key, true), 0, 32);
// Intialize encryption
mcrypt_generic_init ($td, $keyhash, $iv);
while (!feof ($input))
{
$buffer = fread ($input, $buffersize);
// Encrypt the data
$buffer = mdecrypt_generic ($td, $buffer);
// Remove padding for last block
if (feof ($input))
{
$padsize = ord ($buffer[strlen ($buffer) - 1]);
$buffer = substr ($buffer, 0, strlen ($buffer) - $padsize);
}
// Write the encrypted data to $output
fwrite ($output, $buffer, strlen ($buffer));
}
fclose ($input);
fclose ($output);
// Deinitialize encryption module
mcrypt_generic_deinit ($td);
// Close encryption module
mcrypt_module_close ($td);
return true;
}
Run Code Online (Sandbox Code Playgroud)
谁知道如何解决这个问题?我正在使用PHP 5.3和CodeIgniter 2.1(认为这很可能与 CodeIgniter 无关)
看起来你没有安装mcrypt.试试跑步:
sudo yum install php-mcrypt
Run Code Online (Sandbox Code Playgroud)
...来自您实例的命令行.