0

When I try to execute this file, it show me black page..

i start the firebug it shows me that NetworkError: 500 Internal Server Error i tried to solve but cant find any problem here..

so could you help me to find what is the error or problem..??

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);
    }
}
}

When i debug with var_dump(), i found that in function transformFinalBlock

$padding = array_values(unpack('C', substr($text, -1)))[0];

it throw me error like " '[' is unexpected "

Guys, solutions plz...

Sanjay
  • 113
  • 1
  • 5
  • enable display of http error message first. – Raptor Feb 26 '14 at 11:02
  • How do you use this class? A class definition does not do anything by itself! – Mohsenme Feb 26 '14 at 11:12
  • @ShivanRaptor it shows nothing in mozilla, but in IE error shown like syntax error, unexpected '[' in line ----- $padding = array_values(unpack('C', substr($text, -1)))[0]; – Sanjay Feb 26 '14 at 11:31
  • @Mohsenme i include this file in my index.php file & use the function of this file.. – Sanjay Feb 26 '14 at 11:32
  • Can you run other scripts? Do you have .htaccess file (server configuration file) in your directory? – Mohsenme Feb 26 '14 at 20:54
  • @user3181866 learn PHP please. show error by adding `ini_set('display_errors', '1');` in the first line as well as reading this: http://stackoverflow.com/questions/11749043/php-not-displaying-errors-internal-server-error-500 – Raptor Feb 27 '14 at 02:17
  • @ShivanRaptor i said i already did that what you said me, i told also that it not displayed in mozilla but in IE it show me error & what error i got that i also wrote here.. Look at that... – Sanjay Feb 27 '14 at 06:15
  • @Mohsenme nothing that i use.. i just want to run my index file & want to use the function of this.. nothing more.. & what error i got that i also described here.. – Sanjay Feb 27 '14 at 06:17
  • i got the error in following line $padding = array_values(unpack('C', substr($text, -1)))[0]; may be i have to write like $padding = array_values(unpack('C', substr($text, -1))); $padding = $padding[0]; – Sanjay Feb 27 '14 at 06:18
  • What is the exact error you got ? click the magic **edit** button & update your question please. – Raptor Feb 27 '14 at 06:38
  • What php version do you have installed? – Daedalus Feb 27 '14 at 06:49
  • It's a shorthand array syntax, your php version should be >= `5.4.0`, to get it work. – Rikesh Feb 27 '14 at 06:51
  • @Daedalus Apache Version : 2.2.21 PHP Version : 5.3.8 – Sanjay Feb 27 '14 at 06:51

1 Answers1

1

Array de-referencing, which is what you are doing with the line $padding = array_values(unpack('C', substr($text, -1)))[0];, is only possible as of php 5.4, any prior versions, you will have to do the following to access your array:

$arr = array_values(unpack('C', substr($text, -1)));
$padding = $arr[0];
Daedalus
  • 7,586
  • 5
  • 36
  • 61