8

每次我尝试运行 m_decrypt 时,都会抛出以下错误:

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 上运行

4

2 回答 2

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

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

于 2014-03-26T04:42:27.910 回答
8

好的解决了。我输入错误的常量。我改变了我班级的变量,如下所示:

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

希望这可以帮助人们在路上不要猛烈抨击他们的大脑!!

于 2012-12-22T19:26:12.023 回答