note 110435 added to function.mcrypt-encrypt

From: Date: Mon, 22 Oct 2012 10:48:32 +0000
Subject: note 110435 added to function.mcrypt-encrypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-191476@lists.php.net to get a copy of this message
class encrypt { const EXAMPLEKEY1 = "UBeChsDHZOYdbITKz/LXceb3XMPVFOAP"; const EXAMPLEIV1 = "vsrpN/tmchipHza9jldMLVNCowLpkse5WOU8mVTnSOo="; public static function gen_base64_key($bytes = 24, &$strong = null) { return base64_encode(openssl_random_pseudo_bytes($bytes, $strong)); } public static function gen_base64_ivector() { $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $iv = mcrypt_create_iv($iv_size); return base64_encode($iv); } public static function encrypt_text($text, $base64key, $base64ivector) { return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, base64_decode($base64key), bzcompress(trim($text)), MCRYPT_MODE_CBC, base64_decode($base64ivector))); } public static function decrypt_text($text, $base64key, $base64ivector) { return bzdecompress(trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, base64_decode($base64key), base64_decode($text), MCRYPT_MODE_CBC, base64_decode($base64ivector)))); } } $plaintext = "this is a test"; $key = encrypt::gen_base64_key(); $iv = encrypt::gen_base64_ivector(); $cyphertext = encrypt::encrypt_text($plaintext, $key, $iv); $decyphertext = encrypt::decrypt_text($cyphertext, $key, $iv); echo $key . "\n"; echo $iv . "\n"; echo $plaintext . "\n"; echo $cyphertext . "\n"; echo $decyphertext . "\n"; ---- Server IP: 69.147.83.199 Probable Submitter: 82.20.75.197 ---- Manual Page -- http://www.php.net/manual/en/function.mcrypt-encrypt.php Edit -- https://master.php.net/note/edit/110435 Del: integrated -- https://master.php.net/note/delete/110435/integrated Del: useless -- https://master.php.net/note/delete/110435/useless Del: bad code -- https://master.php.net/note/delete/110435/bad+code Del: spam -- https://master.php.net/note/delete/110435/spam Del: non-english -- https://master.php.net/note/delete/110435/non-english Del: in docs -- https://master.php.net/note/delete/110435/in+docs Del: other reasons-- https://master.php.net/note/delete/110435 Reject -- https://master.php.net/note/reject/110435 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#191476) next »