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

search for in the

mhash_count> <Memcache::setServerParams
Last updated: Tue, 27 Nov 2007

view this page in

Funciones Mhash

Introducción

Estas funciones tienen el propósito de trabajar con » mhash. Mhash puede ser usado para crear sumas de verificación, resúmenes de mensajes, códigos de autenticación de mensajes, y más.

Esta es una interfaz con la biblioteca mhash. mhash soporta una amplia variaded de algoritmos hash como MD5, SHA1, GOST, y muchos otros. Para una lista completa de resúmenes criptográficos soportados, refiérase a la documentación de mhash. La regla general es que puede acceder al algoritmo hash desde PHP con MHASH_NOMBRE_DEL_HASH. Por ejemplo, para acceder a TIGER, use la constante PHP MHASH_TIGER.

Note: This extension has been moved to the » PECL repository and is no longer bundled with PHP as of PHP 5.3.0. Esta extensión se considera obsoleta en favor de Hash.

Requisitos

Para usar la extensión, descargue la distribución de mhash desde » su sitio web y siga las instrucciones de instalación incluidas.

Instalación

Necesita compilar PHP con el parámetro --with-mhash[=DIR] para habilitar esta extensión. DIR es el directorio de instalación de mhash.

Configuración en tiempo de ejecución

Esta extensión no tiene directivas de configuración en php.ini.

Tipos de recursos

Esta extensión no tiene ningún tipo de recurso definido.

Constantes predefinidas

Estas constantes están definidas por esta extensión y estarán disponibles solamente cuando la extensión ha sido o bien compilada dentro de PHP o grabada dinámicamente en tiempo de ejecución.

A continuación se encuentra una lista de resúmenes criptográficos soportados en la actualidad por mhash. Si un mecanismo de resumen no se encuentra listado aquí, pero es listado como soportado por mhash, puede asumir con seguridad que esta documentación se encuentra desactualizada.

  • 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

Ejemplos

Example#1 Calcular el resumen MD5 y hmac e imprimirlo como valor hexadecimal

<?php
$entrada 
"que quisiera a cambio de nada?";
$hash mhash(MHASH_MD5$entrada);
echo 
"El valor hash es ".bin2hex ($hash)."<br />\n";
$hash mhash(MHASH_MD5$entrada"Jefe");
echo 
"El valor hmac es ".bin2hex ($hash)."<br />\n";
?>

Esto producirá:

El valor hash es 2386e00b2d014a4b89efb10b0250ac35
El valor hmac es 87367c5cbb5099cf95fcee560d402da4

Table of Contents



mhash_count> <Memcache::setServerParams
Last updated: Tue, 27 Nov 2007
 
add a note add a note User Contributed Notes
mhash
ludicruz at yahoo dot com
07-Jul-2007 11: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 10: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
12-Aug-2005 02: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
22-Jun-2004 08: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
01-Aug-2001 05: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,...

mhash_count> <Memcache::setServerParams
Last updated: Tue, 27 Nov 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites