我正在使用MCrypt.php
include("MCrypt.php");
$crypter = new MCrypt();
MCrypt.php
存在于同一目录中。
当我运行index.php
时,我得到了
致命错误:未找到“MCrypt”类 第5行/home/username/project/index.php
更新:我尝试过只包含MCrypt.php但得到了同样的错误。我尝试重命名为.class.php并得到了同样的错误。
class MCrypt {
private $iv = 'fedcba9876543210'; #Same as in JAVA
private $key = '0123456789abcdef'; #Same as in JAVA
function __construct() {
}
function encrypt($str) {
$iv = $this->iv;
$td = mcrypt_module_open('rijndael-128', '', 'cbc', $iv);
mcrypt_generic_init($td, $this->key, $iv);
$str = $this->padString($str);
$encrypted = mcrypt_generic($td, $str);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return base64_encode($encrypted);
}
function decrypt($code) {
$code = base64_decode($code);
$iv = $this->iv;
$td = mcrypt_module_open('rijndael-128', '', 'cbc', $iv);
mcrypt_generic_init($td, $this->key, $iv);
$decrypted = mdecrypt_generic($td, $code);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return utf8_encode(trim($decrypted));
}
protected function hex2bin($hexdata) {
$bindata = '';
for ($i = 0; $i < strlen($hexdata); $i += 2) {
$bindata .= chr(hexdec(substr($hexdata, $i, 2)));
}
return $bindata;
}
private function padString($source) {
$paddingChar = ' ';
$size = 16;
$x = strlen($source) % $size;
$padLength = $size - $x;
for ($i = 0; $i < $padLength; $i++) {
$source .= $paddingChar;
}
return $source;
}
}
答案 0 :(得分:1)
如果文件名为MCrypt.class.php
,则包含而不是MCrypt.php
,文件为MCrypt.php
。
答案 1 :(得分:1)
你的php文件必须以php开始标记开头。在课前,第一行必须是<?php
<?php
class MCrypt {
...