note 91302 deleted from function.mhash-keygen-s2k by danbrown
| From: | danbrown@php.net | Date: | Thu, 04 Jun 2009 15:45:00 +0000 |
| Subject: | note 91302 deleted from function.mhash-keygen-s2k by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156365@lists.php.net to get a copy of this message | ||
Note Submitter: newton at vsempizdec dot ru
----
To both ray ferguson and gmic, the following code does exact the same as mhash function (you could
change MD5 to SHA1 and properly change block size, but those two are only options if you have no
mhash):
function my_keygen_s2k($_key, $salt, $length){
$blocksize = 16;
$times = (int) $length / $blocksize;
if($length % $blocksize != 0) $times ++;
$return = '';
for($i = 0; $i < $times; $i ++){
$return .= md5(str_repeat(chr(0), $i) . $salt . $_key, true);
}
return $return;
}
The output will be same as mhash_keygen_s2k function.