note 96637 deleted from function.mcrypt-cbc by danbrown

From: Date: Tue, 09 Mar 2010 15:11:27 +0000
Subject: note 96637 deleted from function.mcrypt-cbc by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166829@lists.php.net to get a copy of this message
Note Submitter: filip dot pytloun at ifrit dot eu ---- This simple class could be useful for people who want to work with mcrypt-cbc more often. <?php /** * @author Filip Pytloun * @copyright 2010 */ class Crypter { private $key; private $cipher; /** * @param string $key * @param string $cipher * @return bool */ public function __construct($key = '', $cipher = 'MCRYPT_3DES') { $this->key = $key; $this->cipher = $cipher; return true; } /** * @param string $key * @return bool */ public function setKey($key) { $this->key = $key; return true; } /** * @param string $cipher * return bool */ public function setCipher($cipher) { $this->cipher = $cipher; return true; } /** * @param string $d_string * @param string $key * @param string $cipher * @return string */ public function encrypt($d_string, $key = '', $cipher = '') { if (empty($key)) { $key = $this->key; } if (empty($cipher)) { $cipher = $this->cipher; } $e_string = mcrypt_cbc($cipher,$key,$d_string,MCRYPT_ENCRYPT); return $e_string; } /** * @param string $e_string * @param string $key * @param string $cipher * @return string */ public function decrypt($e_string, $key = '', $cipher = '') { if (empty($key)) { $key = $this->key; } if (empty($cipher)) { $cipher = $this->cipher; } $d_string = mcrypt_cbc($cipher,$key,$d_string,MCRYPT_DECRYPT); return $d_string; } } ?>

« previous php.notes (#166829) next »