Jump to content

Set_mcrypt_cookie


yrstruly
 Share

Recommended Posts

HiThe following code is gicing me this error message: Warning: mcrypt_create_iv() [function.mcrypt-create-iv]: Cannot open source device in C:\xampp\htdocs\exercise\set_mcrypt_cookie.php on line 21Warning: mcrypt_generic_init() [function.mcrypt-generic-init]: Iv size incorrect; supplied length: 0, needed: 32 in C:\xampp\htdocs\exercise\set_mcrypt_cookie.php on line 24Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\exercise\set_mcrypt_cookie.php:21) in C:\xampp\htdocs\exercise\set_mcrypt_cookie.php on line 36Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\exercise\set_mcrypt_cookie.php:21) in C:\xampp\htdocs\exercise\set_mcrypt_cookie.php on line 37The cookie has been sent. Its value is 'Om0MxKySLbPPrC30ovxQJi/i5Q1N5noq08gaaSpCpN8='.What am i doing wrong?<?php # Script 4.5 - set_mcrypt_cookie.php /* This page uses the MCrypt library * to encrypt some data. * The data will then be stored in a cookie, * as will the encryption IV. */ // Create the key: $key = md5('77 public drop-shadow Java'); // Data to be encrypted: $data = 'rosebud'; // Open the cipher: // Using Rijndael 256 in CBC mode. $m = mcrypt_module_open('rijndael-256', '', 'cbc', ''); // Create the IV: // Use MCRYPT_RAND on Windows instead of MCRYPT_DEV_RANDOM. $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($m), MCRYPT_DEV_RANDOM); // Initialize the encryption: mcrypt_generic_init($m, $key, $iv); // Encrypt the data: $data = mcrypt_generic($m, $data); // Close the encryption handler: mcrypt_generic_deinit($m); // Close the cipher: mcrypt_module_close($m); // Set the cookies: setcookie('thing1', base64_encode($data)); setcookie('thing2', base64_encode($iv)); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>A More Secure Cookie</title> </head> <body> <p>The cookie has been sent. Its value is '<?php echo base64_encode($data); ?>'.</p> </body> </html>

Link to comment
Share on other sites

HiThe following code is gicing me this error message: Warning: mcrypt_create_iv() [function.mcrypt-create-iv]: Cannot open source device in C:\xampp\htdocs\exercise\set_mcrypt_cookie.php on line 21Warning: mcrypt_generic_init() [function.mcrypt-generic-init]: Iv size incorrect; supplied length: 0, needed: 32 in C:\xampp\htdocs\exercise\set_mcrypt_cookie.php on line 24Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\exercise\set_mcrypt_cookie.php:21) in C:\xampp\htdocs\exercise\set_mcrypt_cookie.php on line 36Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\exercise\set_mcrypt_cookie.php:21) in C:\xampp\htdocs\exercise\set_mcrypt_cookie.php on line 37The cookie has been sent. Its value is 'Om0MxKySLbPPrC30ovxQJi/i5Q1N5noq08gaaSpCpN8='.What am i doing wrong?<?php # Script 4.5 - set_mcrypt_cookie.php /* This page uses the MCrypt library * to encrypt some data. * The data will then be stored in a cookie, * as will the encryption IV. */ // Create the key: $key = md5('77 public drop-shadow Java'); // Data to be encrypted: $data = 'rosebud'; // Open the cipher: // Using Rijndael 256 in CBC mode. $m = mcrypt_module_open('rijndael-256', '', 'cbc', ''); // Create the IV: // Use MCRYPT_RAND on Windows instead of MCRYPT_DEV_RANDOM. $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($m), MCRYPT_DEV_RANDOM); // Initialize the encryption: mcrypt_generic_init($m, $key, $iv); // Encrypt the data: $data = mcrypt_generic($m, $data); // Close the encryption handler: mcrypt_generic_deinit($m); // Close the cipher: mcrypt_module_close($m); // Set the cookies: setcookie('thing1', base64_encode($data)); setcookie('thing2', base64_encode($iv)); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>A More Secure Cookie</title> </head> <body> <p>The cookie has been sent. Its value is '<?php echo base64_encode($data); ?>'.</p> </body> </html>
Can you just point out for me where is MCRYPT_DEV_RANDOM, cause i dont see it? Please Edited by yrstruly
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...