note 96929 added to mcrypt.examples

From: Date: Tue, 23 Mar 2010 18:49:55 +0000
Subject: note 96929 added to mcrypt.examples
Groups: php.notes 
Request: Send a blank email to php-notes+get-167324@lists.php.net to get a copy of this message
Jizz, Gostei tanto da sua implementação que passei ela para dentro de um objeto. just take a look: :) <?php class Password { private $key = "E4HD9h4DhS23DYfhHemkS3Nf";// 24 bit Key private $iv = "fYfhHeDm";// 8 bit IV private $bit_check=8;// bit amount for diff algor. public function encrypt($text) { $text_num =str_split($text,$this->bit_check); $text_num = $this->bit_check-strlen($text_num[count($text_num)-1]); for ($i=0;$i<$text_num; $i++) {$text = $text . chr($text_num);} $cipher = mcrypt_module_open(MCRYPT_TRIPLEDES,'','cbc',''); mcrypt_generic_init($cipher, $this->key, $this->iv); $decrypted = mcrypt_generic($cipher,$text); mcrypt_generic_deinit($cipher); return base64_encode($decrypted); } public function decrypt($encrypted_text){ $cipher = mcrypt_module_open(MCRYPT_TRIPLEDES,'','cbc',''); mcrypt_generic_init($cipher, $this->key, $this->iv); $decrypted = mdecrypt_generic($cipher,base64_decode($encrypted_text)); mcrypt_generic_deinit($cipher); $last_char=substr($decrypted,-1); for($i=0;$i<$this->bit_check-1; $i++){ if(chr($i)==$last_char){ $decrypted=substr($decrypted,0,strlen($decrypted)-$i); break; } } return $decrypted; } } /*** * DADOS DE TESTE * * @var Password * * $password = new Password(); * * $input = "Teste de senha"; * * $str= $password->encrypt($input); * * echo "Iniciou como: $input <br /> Codificado: $str <br /> Traduzido: ".$password->decrypt($str); * */ ?> other php notes: http://diogobesson.wordpress.com thanks a lot, man! ---- Server IP: 69.147.83.197 Probable Submitter: 201.63.29.114 ---- Manual Page -- http://www.php.net/manual/en/mcrypt.examples.php Edit -- https://master.php.net/note/edit/96929 Del: integrated -- https://master.php.net/note/delete/96929/integrated Del: useless -- https://master.php.net/note/delete/96929/useless Del: bad code -- https://master.php.net/note/delete/96929/bad+code Del: spam -- https://master.php.net/note/delete/96929/spam Del: non-english -- https://master.php.net/note/delete/96929/non-english Del: in docs -- https://master.php.net/note/delete/96929/in+docs Del: other reasons-- https://master.php.net/note/delete/96929 Reject -- https://master.php.net/note/reject/96929 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167324) next »