2012-12-22 96 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; 

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