List Info

Thread: note 71452 added to function.mcrypt-encrypt




note 71452 added to function.mcrypt-encrypt
user name
2006-11-29 20:41:28
And two more similar functions for encrypting and decrypting
cookies:

<?php

function encryptCookie($value){
   if(!$value){return false;}
   $key = 'The Line Secret Key';
   $text = $value;
   $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,
MCRYPT_MODE_ECB);
   $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
   $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key,
$text, MCRYPT_MODE_ECB, $iv);
   return trim(base64_encode($crypttext)); //encode for
cookie
}

function decryptCookie($value){
   if(!$value){return false;}
   $key = 'The Line Secret Key';
   $crypttext = base64_decode($value); //decode cookie
   $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,
MCRYPT_MODE_ECB);
   $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
   $decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key,
$crypttext, MCRYPT_MODE_ECB, $iv);
   return trim($decrypttext);
}

?>
----
Server IP: 203.89.181.184
Probable Submitter: 203.171.40.14
----
Manual Page -- http://www.php.net/manual/en/function.mcrypt-encrypt.php

Edit        -- https://master
.php.net/note/edit/71452
Del: integrated  -- h
ttps://master.php.net/note/delete/71452/integrated
Del: useless     -- http
s://master.php.net/note/delete/71452/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/71452/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/71452/spam
Del: non-english -- 
https://master.php.net/note/delete/71452/non-english
Del: in docs     -- http
s://master.php.net/note/delete/71452/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/71452
Reject      -- https://mast
er.php.net/note/reject/71452
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )