Jump to content

Set_mcrypt_cookie


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 post
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 post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...