Jump to content

Recommended Posts

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

[code]
<?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";

?>
[/code]

i rewrote the script into a class file, like this

[code]
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");
?>
[/code]

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?

Thanks
werty
Link to comment
https://forums.phpfreaks.com/topic/10971-mcrypt_rijndael_256-class-error/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.