每次我尝试运行 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 上运行
最佳答案
好的解决了。我输入的常量是错误的。我这样更改了类(class)的变量:
protected $cipher = "rijndael-256";
protected $mode = "cbc";
希望这能帮助人们在以后的道路上不再胡思乱想!!
关于PHP MCRYPT 不断抛出 Module initialization failed Warning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14005669/