2012-12-22 97 views
8

每次我嘗試運行m_decrypt,我已經拋出了以下錯誤:PHP的mcrypt不斷拋出模塊初始化失敗警告

Warning: mcrypt_get_key_size(): Module initialization failed in /var/www/milo/system/encryption/common.php on line 51 Warning: mcrypt_get_block_size(): Module initialization failed in /var/www/milo/system/encryption/common.php on line 54 Warning: mcrypt_decrypt(): Module initialization failed in /var/www/milo/system/encryption/common.php on line 55 

下面是驅動這一切的代碼:

class encrpt 
{ 
    protected $data; 
    protected $key = "JUST A KEY"; 
    protected $cipher = "MCRYPT_SERPENT_256"; 
    protected $mode = "MCRYPT_MODE_CBC"; 

    public function m_encrypt($data) 
    { 
     return (string) 
     base64_encode(
      mcrypt_encrypt(
      $this->cipher, 
      substr(md5($this->key),0,mcrypt_get_key_size($this->cipher, $this->mode)), 
      $data, 
      $this->mode, 
      substr(md5($this->key),0,mcrypt_get_block_size($this->cipher, $this->mode)) 
     ) 
     ); 
    } 

    public function m_decrypt($data) 
    { 
     return (string) 
      mcrypt_decrypt(
      $this->cipher, 
      substr(md5($this->key),0,mcrypt_get_key_size($this->cipher, $this->mode)), 
      base64_decode($data), 
      $this->mode, 
      substr(md5($this->key),0,mcrypt_get_block_size($this->cipher, $this->mode)) 
     ); 
    } 
} 

我不知道我錯過了什麼。我的php-mcrypt模塊是否損壞或缺少依賴關係?我運行在PHP 5.3上

+0

重複http://stackoverflow.com/questions/4809611/problem-with-mcrypt-installation –

+0

看到它,而不是一個有效的或有用的答案,形狀或形式 –

+0

那麼,你的答案不是更多或者更少有效或者以任何方式有用,因爲它基本上具有相同的內容。 –

回答

8

好的解決了它。我把常量放錯了。我改變了我的班級的變數,如下:

protected $cipher = "rijndael-256"; 
protected $mode = "cbc"; 

希望這可以幫助人們從不打他們的大腦!

7
protected $cipher = MCRYPT_SERPENT_256; 
protected $mode = MCRYPT_MODE_CBC; 

那些是常量 - 不要使用引號。