FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[Resolved] Cookie Encryption





thnn
I am trying to two-way encrypt the data in a cookie so that a user cannot change it. However I do not want to use MD5 as it is one way. I also do not want to use rot13 because it is insecure. Does anyone know if MCrypt is installed on the server?

Also does anyone know of anyway I could two-way encrypt the data in a cookie.
thnn
OK i worked out i need to use MCrypt. I just though it would share how I did it with everyone.

Code:
<?php

       function cookieencode($input)
       {
       $key = "yourkey";

       $td = mcrypt_module_open('blowfish', '', 'ecb', '');
       $ks = mcrypt_enc_get_key_size($td);
       $key = substr($key, 0, $ks);
       $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
       mcrypt_generic_init($td, $key, $iv);
       
       //do the encrpyting
       $encrypted_data = mcrypt_generic($td, $input);
       //end the system
       mcrypt_generic_deinit($td);
       mcrypt_module_close($td);
       //return the results
       return $encrypted_data;
       }

       function cookiedecode($input)
       {
       $key = "yourkey";

       $td = mcrypt_module_open('blowfish', '', 'ecb', '');
       $ks = mcrypt_enc_get_key_size($td);
       $key = substr($key, 0, $ks);
       $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
       mcrypt_generic_init($td, $key, $iv);
       
       //do the decrpyting
       $decrypt = mdecrypt_generic($td, $input);
       //end the system
       mcrypt_generic_deinit($td);
       mcrypt_module_close($td);
       //return the results
       return $decrypt;
       }
   
?>


Then you can call the different functions depending on what you want to do. Example to encode you would call cookieencode or to decode you would call cookiedecode.
Related topics
Logout problem (Cookie?)
Points and FRIH$ -- RESOLVED --
[RESOLVED]Resend Account Details Please!
Php - Basic Encryption site
Why I cant open some security website ?
cookie problems?
Email Encryption - Do you / would you use it?
Need password protected page paying - 60 FRIH$
Best Encryption Software
PhpBB Ranks <RESOLVED>
explorer.exe
Resolved
[php] encryption
Cookie problem
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.