<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Mhash Functions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="函数参考" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="Memcache::setServerParams" HREF="function.memcache-setserverparams.html"><LINK REL="NEXT" TITLE="mhash_count" HREF="function.mhash-count.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="reference" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.memcache-setserverparams.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.mhash-count.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.mhash" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >LXXXVII. Mhash Functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN118942" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="mhash.intro" >简介</A ></H1 ><P > These functions are intended to work with <A HREF="http://mhash.sourceforge.net/" TARGET="_top" >mhash</A >. Mhash can be used to create checksums, message digests, message authentication codes, and more. </P ><P > This is an interface to the mhash library. mhash supports a wide variety of hash algorithms such as MD5, SHA1, GOST, and many others. For a complete list of supported hashes, refer to the documentation of mhash. The general rule is that you can access the hash algorithm from PHP with MHASH_HASHNAME. For example, to access TIGER you use the PHP constant MHASH_TIGER. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > 本扩展已被移动到 <A HREF="http://pecl.php.net" TARGET="_top" >PECL</A > 库中且自以下版本起不再被绑定到 PHP 中:5.3.0. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="mhash.requirements" >需求</A ></H1 ><P > To use it, download the mhash distribution from <A HREF="http://mhash.sourceforge.net/" TARGET="_top" >its web site</A > and follow the included installation instructions. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="mhash.installation" >安装</A ></H1 ><P > You need to compile PHP with the <CODE CLASS="option" >--with-mhash[=DIR]</CODE > parameter to enable this extension. DIR is the mhash install directory. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="mhash.configuration" >运行时配置</A ></H1 ><P >本扩展模块在 <TT CLASS="filename" >php.ini</TT > 中未定义任何配置选项。</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="mhash.resources" >资源类型</A ></H1 ><P >本扩展模块未定义任何资源类型。</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="mhash.constants" >预定义常量</A ></H1 ><P >以下常量由本扩展模块定义,因此只有在本扩展模块被编译到 PHP 中,或者在运行时被动态加载后才有效。</P ><P > Here is a list of hashes which are currently supported by mhash. If a hash is not listed here, but is listed by mhash as supported, you can safely assume that this documentation is outdated. <P ></P ><UL ><LI ><P > <TT CLASS="constant" ><B >MHASH_ADLER32</B ></TT > </P ></LI ><LI ><P > <TT CLASS="constant" ><B >MHASH_CRC32</B ></TT > </P ></LI ><LI ><P > <TT CLASS="constant" ><B >MHASH_CRC32B</B ></TT > </P ></LI ><LI ><P > <TT CLASS="constant" ><B >MHASH_GOST</B ></TT > </P ></LI ><LI ><P > <TT CLASS="constant" ><B >MHASH_HAVAL128</B ></TT > </P ></LI ><LI ><P > <TT CLASS="constant" ><B >MHASH_HAVAL160</B ></TT > </P ></LI ><LI ><P > <TT CLASS="constant" ><B >MHASH_HAVAL192</B ></TT > </P ></LI ><LI ><P > <TT CLASS="constant" ><B >MHASH_HAVAL256</B ></TT > </P ></LI ><LI ><P > <TT CLASS="constant" ><B >MHASH_MD4</B ></TT > </P ></LI ><LI ><P > <TT CLASS="constant" ><B >MHASH_MD5</B ></TT > </P ></LI ><LI ><P > <TT CLASS="constant" ><B >MHASH_RIPEMD160</B ></TT > </P ></LI ><LI ><P > <TT CLASS="constant" ><B >MHASH_SHA1</B ></TT > </P ></LI ><LI ><P > <TT CLASS="constant" ><B >MHASH_SHA256</B ></TT > </P ></LI ><LI ><P > <TT CLASS="constant" ><B >MHASH_TIGER</B ></TT > </P ></LI ><LI ><P > <TT CLASS="constant" ><B >MHASH_TIGER128</B ></TT > </P ></LI ><LI ><P > <TT CLASS="constant" ><B >MHASH_TIGER160</B ></TT > </P ></LI ></UL > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="mhash.examples" >范例</A ></H1 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN119022" ></A ><P ><B >例 1. Compute the MD5 digest and hmac and print it out as hex</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$input </font><font color="#007700">= </font><font color="#DD0000">"what do ya want for nothing?"</font><font color="#007700">;<br /></font><font color="#0000BB">$hash </font><font color="#007700">= </font><font color="#0000BB">mhash</font><font color="#007700">(</font><font color="#0000BB">MHASH_MD5</font><font color="#007700">, </font><font color="#0000BB">$input</font><font color="#007700">);<br />echo </font><font color="#DD0000">"The hash is " </font><font color="#007700">. </font><font color="#0000BB">bin2hex</font><font color="#007700">(</font><font color="#0000BB">$hash</font><font color="#007700">) . </font><font color="#DD0000">"<br />\n"</font><font color="#007700">;<br /></font><font color="#0000BB">$hash </font><font color="#007700">= </font><font color="#0000BB">mhash</font><font color="#007700">(</font><font color="#0000BB">MHASH_MD5</font><font color="#007700">, </font><font color="#0000BB">$input</font><font color="#007700">, </font><font color="#DD0000">"Jefe"</font><font color="#007700">);<br />echo </font><font color="#DD0000">"The hmac is " </font><font color="#007700">. </font><font color="#0000BB">bin2hex</font><font color="#007700">(</font><font color="#0000BB">$hash</font><font color="#007700">) . </font><font color="#DD0000">"<br />\n"</font><font color="#007700">;<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P > This will produce: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >The hash is d03cb659cbf9192dcd066272249f8412 The hmac is 750c783e6ab0b503eaa86e310a5db738</PRE ></TD ></TR ></TABLE > </P ></DIV ></TD ></TR ></TABLE > </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >目录</B ></DT ><DT ><A HREF="function.mhash-count.html" >mhash_count</A > -- Get the highest available hash id</DT ><DT ><A HREF="function.mhash-get-block-size.html" >mhash_get_block_size</A > -- Get the block size of the specified hash</DT ><DT ><A HREF="function.mhash-get-hash-name.html" >mhash_get_hash_name</A > -- Get the name of the specified hash</DT ><DT ><A HREF="function.mhash-keygen-s2k.html" >mhash_keygen_s2k</A > -- Generates a key</DT ><DT ><A HREF="function.mhash.html" >mhash</A > -- Compute hash</DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.memcache-setserverparams.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.mhash-count.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Memcache::setServerParams</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >mhash_count</TD ></TR ></TABLE ></DIV ></BODY ></HTML >