Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: mhash - Manual
[go: Go Back, main page]

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

search for in the

mhash_count" width="11" height="7"/> <Memcache::setServerParams
Last updated: Sun, 25 Nov 2007

view this page in

Mhash 関数

導入

以下の関数は、» mhash と組み合わせて 動作することを前提としています。mhashは、チェックサム、メッセージ ダイジェスト、メッセージ認証コード等を作成するために使用することが できます。

この関数は、mhash ライブラリへのインターフェースです。 mhash は、MD5, SHAl, GOST や他の多くの方法といった広範なハッシュ アルゴリズムをサポートします。サポートされるハッシュの全一覧に ついては、mhash のドキュメントを参照してください。一般的な規則として、 特定のハッシュアルゴリズムは、PHP から定数「MHASH_ハッシュ名」で アクセス可能です。例えば、TIGER の場合、PHP 定数 MHASH_TIGER を 使用します。

注意: この拡張モジュールは » PECL レポジトリに移動 されており、以下のバージョン以降 PHP にバンドルされなくなっています。 PHP 5.3.0. この拡張モジュールの後継版は Hash です。

要件

mhash を使用するには、mhash の配布ファイルを » mhash の Web サイト から ダウンロードし、その中のインストール用の指示に従ってください。

インストール手順

この拡張機能を使用するには、PHP に --with-mhash[=DIR] パラメータを付けて コンパイルする必要があります。DIR は mhash インストールディレクトリです。

実行時設定

設定ディレクティブは定義されていません。

リソース型

リソース型は定義されていません。

定義済み定数

以下の定数が定義されています。 この関数の拡張モジュールが PHP 組み込みでコンパイルされているか、 実行時に動的にロードされている場合のみ使用可能です。

以下に現在 mhash によりサポートされているハッシュの一覧を示します。 mhash にサポートされているハッシュがこのリストにない場合は、 このドキュメントが古いと考えてください。

  • 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

Example#1 MD5 ダイジェストと hmac を計算し、16 進数で出力する

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

この例の出力は次のようになります。

The hash is d03cb659cbf9192dcd066272249f8412 
The hmac is 750c783e6ab0b503eaa86e310a5db738 

目次



add a note add a note User Contributed Notes
mhash
alexey dot kupershtokh at gmail dot com
27-Dec-2007 09: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
08-Jul-2007 05: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 05: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 08: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 02: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 11: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