note 51085 deleted from function.md5 by mazzanet
| From: | mazzanet@php.net | Date: | Mon, 03 Oct 2005 09:40:15 +0000 |
| Subject: | note 51085 deleted from function.md5 by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-96266@lists.php.net to get a copy of this message | ||
Note Submitter: robbie [at] averill [dot] co [dot] nz
----
If you are looking for other similar hashing functions, you can use the mhash lib: http://www.php.net/mhash.
It includes around 25 hashing algorithms including MD5, MD4 and SHA1.
Here's a little example of how to use mhash:
<?
$num_of_algs = mhash_count();
$string = "apples are nice";
for($i=0; $i<=$num_of_algs; $i++){
$name = @mhash_get_hash_name($i);
$hash = @mhash($i, $string);
# hash is in raw decimal form
$hex = bin2hex($hash);
# hex is in hexadecimal form
echo "<p>Hashed with: ".$name."<br /><b>Binary:</b>
".$hash."<br /><b>Hexadecimal</b>: ".$hex."</p>";
}
?>
@ used before function call incase a hash doesn't exist when it should. You can also use
if($hash) echo "<p>...
This will output both the raw binary output of each hash, and the hexadecimal output. You will
notice that the hashing algorithm "WHIRLPOOL" has a very long length, so it might be a
better choice over MD5.