note 71452 deleted from function.mcrypt-encrypt by nikic

From: Date: Sat, 09 Nov 2013 11:11:47 +0000
Subject: note 71452 deleted from function.mcrypt-encrypt by nikic
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197473@lists.php.net to get a copy of this message
Note Submitter: davidwhthomas at gmail ---- 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); } ?>

« previous php.notes (#197473) next »