note 87526 added to function.mcrypt-encrypt

From: Date: Tue, 09 Dec 2008 05:06:44 +0000
Subject: note 87526 added to function.mcrypt-encrypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-147939@lists.php.net to get a copy of this message
There's a lot of old information on this page, for those that just want some simple encryption/decryption try this out. <? define('SALT', 'whateveryouwant'); function encrypt($text) { return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SALT, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)))); } function decrypt($text) { return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SALT, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))); } ?> then try out something like: <? $encryptedmessage = encrypt("You're my only hope!"); echo decrypt($encryptedmessage); ?> It should return your original message. You can remove the base64_encode and base64_decode from the functions if you want to save space on the encoded string, I use it to simplify database storage. ---- Server IP: 208.69.120.35 Probable Submitter: 76.114.198.107 ---- Manual Page -- http://www.php.net/manual/en/function.mcrypt-encrypt.php Edit -- https://master.php.net/note/edit/87526 Del: integrated -- https://master.php.net/note/delete/87526/integrated Del: useless -- https://master.php.net/note/delete/87526/useless Del: bad code -- https://master.php.net/note/delete/87526/bad+code Del: spam -- https://master.php.net/note/delete/87526/spam Del: non-english -- https://master.php.net/note/delete/87526/non-english Del: in docs -- https://master.php.net/note/delete/87526/in+docs Del: other reasons-- https://master.php.net/note/delete/87526 Reject -- https://master.php.net/note/reject/87526 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#147939) next »