note 62876 added to function.mcrypt-generic

From: Date: Sat, 11 Mar 2006 20:55:48 +0000
Subject: note 62876 added to function.mcrypt-generic
Groups: php.notes 
Request: Send a blank email to php-notes+get-105278@lists.php.net to get a copy of this message
I was able get php and perl to play together with blowfish using cipher block chaining. The blowfish key needs to be atleast 8 chars (even though blowfish min is 8 bits, perl didn't like keys smaller than 8 chars) and max 56. The iv must be exactly 8 chars and padding needs to be null because php pads with nulls. Also, php needs libmcrypt >= 2.4.9 to be compatible with perl. PERL ---- use Crypt::CBC; $cipher = Crypt::CBC->new( {'key' => 'my secret key', 'cipher'=> 'Blowfish', 'iv' => '12345678', 'regenerate_key' => 0, 'padding' => 'null', 'prepend_iv' => 0 }); $cc = 'my secret text'; $encrypted = $cipher->encrypt($cc); $decrypted = $cipher->decrypt($encrypted); print "encrypted : ".$encrypted; print "<br>"; print "decrypted : ".$decrypted; PHP --- $cc = 'my secret text'; $key = 'my secret key'; $iv = '12345678'; $cipher = mcrypt_module_open(MCRYPT_BLOWFISH,'','cbc',''); mcrypt_generic_init($cipher, $key, $iv); $encrypted = mcrypt_generic($cipher,$cc); mcrypt_generic_deinit($cipher); mcrypt_generic_init($cipher, $key, $iv); $decrypted = mdecrypt_generic($cipher,$encrypted); mcrypt_generic_deinit($cipher); echo "encrypted : ".$encrypted; echo "<br>"; echo "decrypted : ".$decrypted; ---- Server IP: 216.194.113.175 Probable Submitter: 12.108.126.131 ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.mcrypt-generic.php Edit -- http://master.php.net/note/edit/62876 Del: integrated -- http://master.php.net/note/delete/62876/integrated Del: useless -- http://master.php.net/note/delete/62876/useless Del: bad code -- http://master.php.net/note/delete/62876/bad+code Del: spam -- http://master.php.net/note/delete/62876/spam Del: non-english -- http://master.php.net/note/delete/62876/non-english Del: in docs -- http://master.php.net/note/delete/62876/in+docs Del: other reasons-- http://master.php.net/note/delete/62876 Reject -- http://master.php.net/note/reject/62876 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#105278) next »