Jump to content


Photo

MCRYPT_RIJNDAEL_256 class error


  • Please log in to reply
No replies to this topic

#1 werty37

werty37
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 01 June 2006 - 05:30 PM

Hi
So i found this script in a website. It works like charm...

<?php

// Designate string to be encrypted
$string = 'Applied Cryptography, by Bruce Schneier, is a wonderful cryptography reference.';

// Encryption/decryption key
$key = 'Four score and twenty years ago';

// Encryption Algorithm
$cipher_alg = MCRYPT_RIJNDAEL_256;

// Create the initialization vector for added security.
$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, MCRYPT_MODE_ECB), MCRYPT_RAND);

// Output original string
print "Original string: $string <p>";

// Encrypt $string
$encrypted_string = mcrypt_encrypt($cipher_alg, $key, $string, MCRYPT_MODE_CBC, $iv);

// Convert to hexadecimal and output to browser
print "Encrypted string: ".bin2hex($encrypted_string)."<p>";

$decrypted_string = mcrypt_decrypt($cipher_alg, $key, $encrypted_string, MCRYPT_MODE_CBC, $iv);

print "Decrypted string: $decrypted_string";

?>

i rewrote the script into a class file, like this

class securedata
{
var $key = "Four score and twenty years ago";
var $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDALE_256, MCRYPT_MODE_ECB), MCRYPT_RAND);

function encrypt($STR)
{
return bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $STR, MCRYPT_MODE_CBC, $iv));
}

function decrypt($STR)
{
return mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $STR, MCRYPT_MODE_CBC, $iv);
}

}

$sd = new securedata();
echo $sd->encrypt("MyMessage");
echo "<br>";
echo $sd->decrypt("MyMessage");
?>

When i run the script i keep getting the message
Parse error: syntax error, unexpected '(', expecting ',' or ';' in /var/www/emites/securedata_inc.php on line 11
in this line:
-> var $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, MCRYPT_MODE_ECB), MCRYPT_RAND);

What is wrong?

Thanks
werty




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users