note 105173 added to function.mcrypt-encrypt

From: Date: Mon, 01 Aug 2011 12:57:05 +0000
Subject: note 105173 added to function.mcrypt-encrypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-182042@lists.php.net to get a copy of this message
If you want to be interoperable with other PKCS #7 padding implementations, like the Legion of the Bouncy Castle Java cryptography APIs, you should always pad, that is a 8-byte (block size) padding should be added, even if not necessary: <?php function encrypt($str, $key) { $block = mcrypt_get_block_size('des', 'ecb'); $pad = $block - (strlen($str) % $block); $str .= str_repeat(chr($pad), $pad); return mcrypt_encrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB); } function decrypt($str, $key) { $str = mcrypt_decrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB); $block = mcrypt_get_block_size('des', 'ecb'); $pad = ord($str[($len = strlen($str)) - 1]); return substr($str, 0, strlen($str) - $pad); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 92.27.17.145 ---- Manual Page -- http://www.php.net/manual/en/function.mcrypt-encrypt.php Edit -- https://master.php.net/note/edit/105173 Del: integrated -- https://master.php.net/note/delete/105173/integrated Del: useless -- https://master.php.net/note/delete/105173/useless Del: bad code -- https://master.php.net/note/delete/105173/bad+code Del: spam -- https://master.php.net/note/delete/105173/spam Del: non-english -- https://master.php.net/note/delete/105173/non-english Del: in docs -- https://master.php.net/note/delete/105173/in+docs Del: other reasons-- https://master.php.net/note/delete/105173 Reject -- https://master.php.net/note/reject/105173 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#182042) next »