downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

mhash_count> <Memcache::setCompressThreshold
[edit] Last updated: Mon, 01 Nov 2010

view this page in

LXXXIII. Hash

Introduction

Ces fonctions ont été prévues pour fonctionner avec mhash. Mhash peut être utilisée pour créer une somme de contrôle, un hachage et bien plus.

Cet ensemble de fonctions représente une interface avec la bibliothèque mhash. Mhash accepte un grand nombre d'algorithmes différents, tels MD5, SHA1, GOST et bien d'autres. Pour une liste complète des hashes supportés, reportez-vous à la documentation de mhash. La règle générale est que vous pouvez accéder à un algorithme depuis PHP avec la constante MHASH_NOMDUHASH. Par exemple, pour accéder à l'algorithme TIGER, vous pouvez utiliser la constante MHASH_TIGER.

Pré-requis

Pour l'utiliser, téléchargez les distributions de mhash depuis ce site internet et suivez les instructions d'installation incluses.

Installation

Vous aurez besoin de compiler PHP avec l'option --with-mhash[=DIR] pour activer cette extension. DIR est le chemin du dossier d'installation de la bibliothèque MHASH.

Configuration à l'exécution

Cette extension ne définit aucune directive de configuration.

Types de ressources

Cette extension ne définit aucune ressource.

Constantes pré-définies

Ces constantes sont définies par cette extension, et ne sont disponibles que si cette extension a été compilée avec PHP, ou bien chargée au moment de l'exécution.

Voici une liste des modes qui sont supportés par mhash. Toutes les constantes ne sont pas ici, et vous pouvez supposer que cette documentation n'est plus à jour.

  • MHASH_ADLER32

  • MHASH_CRC32

  • MHASH_CRC32B

  • MHASH_GOST

  • MHASH_HAVAL128

  • MHASH_HAVAL160

  • MHASH_HAVAL192

  • MHASH_HAVAL256

  • MHASH_MD4

  • MHASH_MD5

  • MHASH_RIPEMD160

  • MHASH_SHA1

  • MHASH_SHA256

  • MHASH_TIGER

  • MHASH_TIGER128

  • MHASH_TIGER160

Exemples

Exemple 1. Calcule le MD5 et le hmac, puis l'affiche comme un hexadécimal

<?php
$input
= "what do ya want for nothing?";
$hash = mhash (MHASH_MD5, $input);
echo
"Le hash vaut ".bin2hex ($hash)."<br />\n";
$hash = mhash (MHASH_MD5, $input, "Jefe");
echo
"Le hmac vaut ".bin2hex ($hash)."<br />\n";
?>

L'exemple ci-dessus va afficher :

Le hmac vaut d03cb659cbf9192dcd066272249f8412 
Le hmac vaut 750c783e6ab0b503eaa86e310a5db738

Table des matières
mhash_count -- retourne l'identifiant maximal de hash
mhash_get_block_size -- Retourne la taille de bloc du hash
mhash_get_hash_name -- Retourne le nom du hash
mhash_keygen_s2k -- Génère une clé
mhash -- Calcule un hash


mhash_count> <Memcache::setCompressThreshold
[edit] Last updated: Mon, 01 Nov 2010
 
add a note add a note User Contributed Notes Hash
alexey dot kupershtokh at gmail dot com 27-Dec-2007 04:48
There's a class for generating TTH compatible with DC clients (DC++, StrongDC, ...) which uses mhash() with tiger algorithm:
http://kupershtokh.blogspot.com/2007/12/on-phpclub.html
ludicruz at yahoo dot com 07-Jul-2007 01:41
to robert at mediamonks dot com

This will work better, in your function you can just use the constant function to pull in the actual value of MHASH_SHA512 or whatever.

function getHashNotWorking($argStrHashMethod, $argStrString)
{
$strHashMethod = 'MHASH_' . $argStrHashMethod;
$strHashedString = bin2hex(mhash(constant($strHashMethod), $argStrString));

return $strHashedString;
}

now:

echo getHashNotWorking('SHA512', 'some string');

works how you want it.
robert at mediamonks dot com 06-Dec-2006 12:44
function getHashNotWorking($argStrHashMethod, $argStrString)
{
$strHashMethod = 'MHASH_' . $argStrHashMethod;
$strHashedString = bin2hex(mhash($strHashMethod, $argStrString));

return $strHashedString;
}

echo getHashNotWorking('SHA512', 'some string');

This will return an error about the mhash function expecting a long type instead of a string.

=============================

for ($intI = 0; $intI <= mhash_count(); $intI++)
{
$arrHashTypes[mhash_get_hash_name($intI)] = $intI;
}

function getHashWorking($argStrType, $argStrString)
{
global $arrHashTypes;
$strHashedString = bin2hex(mhash($arrHashTypes[$argStrType], $argStrString));

return $strHashedString;
}

echo getHashWorking('SHA512', 'some string');

This will return the hash with the desired hash method
brentdothansenatgmaildotcom 11-Aug-2005 04:43
Since it seems that the tiger hash bug has been labeled "bogus" here is a fix to give a correct result.  I'm not a binary expert so if you come up with a better fix please let us know. Just do your MHASH_TIGER as normal then send the unaltered binary into tigerfix and you get a proper HEX return.

function tigerfix ($binary_hash) {
     $my_split = str_split($binary_hash,8);
     $my_tiger ="";
     foreach($my_split as $key => $value) {
        $my_split[$key] = strrev($value);
        $my_tiger .= $my_split[$key];
     }
    $my_tiger_hex = bin2hex($my_tiger);
    return $my_tiger_hex;
}
m1tk4 at hotmail dot com 21-Jun-2004 10:43
To enable mhash on RHEL/Fedora Core/other RPM-based Linuxes without rebuilding PHP, get the php-mhash and mhash RPMs at http://phprpms.sourceforge.net/mhash
31-Jul-2001 07:13
MHASH_HAVAL256 , MHASH_HAVAL192, etc...
refers to the HAVAL hash with 3 rounds.

To use HAVAL with 4 or 5 rounds, you have to
recompile the mhash library and either add
new hash names, or just change in mhash.c
the definitions of MHASH_HAVAL256,...

 
show source | credits | sitemap | contact | advertising | mirror sites