【发布时间】:2014-02-26 10:58:18
【问题描述】:
当我尝试执行此文件时,它显示黑页..
我启动了萤火虫,它告诉我 NetworkError: 500 Internal Server Error 我试图解决,但在这里找不到任何问题..
所以你能帮我找出错误或问题是什么..?
class DesEncryptor
{
protected $_key;
protected $_iv;
protected $_blocksize = 8;
protected $_encrypt;
protected $_cipher;
/**
* Creates a symmetric Data Encryption Standard (DES) encryptor object
* with the specified key and initialization vector.
*
* @param $key
* @param $iv
* @param bool $encrypt
*/
public function __construct($key, $iv, $encrypt = true)
{
$this->_key = $key;
$this->_iv = $iv;
$this->_encrypt = $encrypt;
$this->_cipher = mcrypt_module_open(MCRYPT_DES, '', MCRYPT_MODE_CBC, '');
mcrypt_generic_init($this->_cipher, $this->_key, $this->_iv);
}
public function __destruct()
{
mcrypt_generic_deinit($this->_cipher);
mcrypt_module_close($this->_cipher);
}
/**
* Transforms the specified region of the specified byte array using PCKS7 padding.
* @param $text
* @return string
*/
public function transformFinalBlock($text)
{
if ($this->_encrypt)
{
$padding = $this->_blocksize - strlen($text) % $this->_blocksize;
$text .= str_repeat(pack('C', $padding), $padding);
}
$text = $this->transformBlock($text);
if (!$this->_encrypt)
{
$padding = array_values(unpack('C', substr($text, -1)))[0];
$text = substr($text, 0, strlen($text) - $padding);
}
return $text;
}
/**
* Transforms the specified region of the specified byte array.
* @param $text
* @return string
*/
public function transformBlock($text)
{
if ($this->_encrypt)
{
return mcrypt_generic($this->_cipher, $text);
}
else
{
return mdecrypt_generic($this->_cipher, $text);
}
}
}
当我使用 var_dump() 进行调试时,我发现在函数 transformFinalBlock 中
$padding = array_values(unpack('C', substr($text, -1)))[0];
它会抛出类似“'[' is unexpected”这样的错误
伙计们,请解决...
【问题讨论】:
-
先启用http错误信息的显示
-
你如何使用这个类?类定义本身不会做任何事情!
-
@ShivanRaptor 它在 mozilla 中什么也没有显示,但在 IE 错误中显示为语法错误,意外的 '[' in line ----- $padding = array_values(unpack('C', substr($文本,-1)))[0];
-
@Mohsenme 我将此文件包含在我的 index.php 文件中并使用此文件的功能..
-
你能运行其他脚本吗?您的目录中有 .htaccess 文件(服务器配置文件)吗?