2012-05-15 6 views
3

파일을 해독하는 데 사용하는 PHP 함수 (PHP 5.3 사용)를 사용했으나 잘 작동했지만 Amazon EC2 (Amazon Linux Image 2012.3 기반)로 옮겼습니다. mcrypt 설치가 손상되었거나 전혀 사용할 수없는 것 같습니다.PHP mcrypt_module_open이 500 오류를 발생합니다.

초기 테스트에서 파일 암호 해독은 작은 파일에서는 작동하지만 20MB + 파일 (특히 큰 크기는 아님)에서 작동하지 않는다고 제안합니다.

나는 에 500 오류의 원인이되는이 라인, (나는 하지mcrypt_module_open is undefined을 얻고을,불과 500 서버 오류)

$td = mcrypt_module_open ('rijndael-128', '', 'cbc', ''); 

이상한 것은, 내가 확인을 아래로 문제를 추적 /etc/php.ini, mcrypt가 전혀 보이지 않습니다. (물론 정확한 php.ini/path를보고 있다고 가정하십시오.)

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; 
} 

누구나 그 문제를 해결할 수 있습니다. CodeIgniter 2.1에서 PHP 5.3을 사용하고 있습니다. (이것이 가장 가능성이 있다고 생각합니다.) 관련 없음 to CodeIgniter

+1

'var_dump (function_exists ('mcrypt_module_open')); 그것은 'TRUE'라고 말합니다. 에러 로그는 무엇을 말합니까? – DaveRandom

+0

아니요,'bool (false)'라고 말합니다. 그래서 모듈을 설치하거나 활성화 할 필요가 있습니까? – TheDude

+1

예, mcrypt가 설치되어 있지 않은 것 같습니다. 인스턴스의 명령 줄에서'sudo yum install php-mcrypt'를 실행 해보십시오. – DaveRandom

답변

5

mcrypt가 설치되지 않은 것 같습니다. 다음을 실행 해보십시오.

sudo yum install php-mcrypt 

... 인스턴스의 명령 줄에서 실행하십시오.

+0

mac osx (yostemite 최신)은 무엇입니까? 또한 mcrypt 모듈도 설치되었지만 여전히 "AES.php"를 사용하여 500 개의 내부 서버 오류가 발생했습니다 .. function mcrypt_encrypt() – idleMind

+0

@idleMind 전체 오류 메시지없이 couldn 심지어 추측해도 위험하지 않습니다 ... – DaveRandom

관련 문제