note 114141 added to function.mcrypt-encrypt

From: Date: Wed, 15 Jan 2014 22:53:45 +0000
Subject: note 114141 added to function.mcrypt-encrypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-198245@lists.php.net to get a copy of this message
I was trying (and succeeded) to encrypt and decrypt in JAVA, pass it to php, and do it again,without corrupting data when I noticed something interesting. So, my code goes like this: $data = 'one'; $key = '1234567890123456'; function encrypt($data, $key){ return base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" ) ); } function decrypt($data, $key){ $decode = base64_decode($data); return mcrypt_decrypt( MCRYPT_RIJNDAEL_128, $key, $decode, MCRYPT_MODE_CBC, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" ); } $encrypted = encrypt($data, $key); $decrypted= decrypt($encrypted, $key); //In the beginning, I thought something's wrong, because I did '===' comparison between $decrypted and $data. It didn't work (but later started working, again, dont know why...) So, I dumped both: var_dump($data); var_dump($decrypted); //Results: string(16) "one" string(16) "one" //Clearly, the length of both is 3, not 16. Just wanted to let you know what could happen, and I really don't know if this is a bug... Thanks, S. ---- Server IP: 72.52.91.14 Probable Submitter: 72.52.91.14 ---- Manual Page -- http://php.net/manual/en/function.mcrypt-encrypt.php Edit -- https://master.php.net/note/edit/114141 Del: integrated -- https://master.php.net/note/delete/114141/integrated Del: useless -- https://master.php.net/note/delete/114141/useless Del: bad code -- https://master.php.net/note/delete/114141/bad+code Del: spam -- https://master.php.net/note/delete/114141/spam Del: non-english -- https://master.php.net/note/delete/114141/non-english Del: in docs -- https://master.php.net/note/delete/114141/in+docs Del: other reasons-- https://master.php.net/note/delete/114141 Reject -- https://master.php.net/note/reject/114141 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198245) next »