Jump to content


This topic is now archived and is closed to further replies.


MCRYPT_RIJNDAEL_256 class error

Recommended Posts

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


// 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
[b]Parse error: syntax error, unexpected '(', expecting ',' or ';' in /var/www/emites/securedata_inc.php on line 11[/b]
in this line:
-> var $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, MCRYPT_MODE_ECB), MCRYPT_RAND);

What is wrong?


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.