werty37 Posted June 1, 2006 Share Posted June 1, 2006 HiSo 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 stringprint "Original string: $string <p>";// Encrypt $string$encrypted_string = mcrypt_encrypt($cipher_alg, $key, $string, MCRYPT_MODE_CBC, $iv);// Convert to hexadecimal and output to browserprint "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?Thankswerty Link to comment https://forums.phpfreaks.com/topic/10971-mcrypt_rijndael_256-class-error/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.