当我尝试执行此文件时,它向我显示黑色页面。.

我启动firebug它向我显示NetworkError:500内部服务器错误 我试图解决,但在这里找不到任何问题。.

所以你能帮我找到什么是错误或问题。.??

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];

它给我带来了错误,比如"'['是意外的"

伙计们,解决方案plz。..

有帮助吗?

解决方案

数组去引用,这就是你正在做的行 $padding = array_values(unpack('C', substr($text, -1)))[0];, ,只有在 php5.4, ,任何以前的版本,你将不得不执行以下操作来访问你的阵列:

$arr = array_values(unpack('C', substr($text, -1)));
$padding = $arr[0];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top