php-doc-en/functions/mhash.sgml
cslawi 9256eb3b12 Normalized according to the DocBook 3.1 DTD. This mostly just adds
closing tags and attribute quotes, but lets a stock 3.1 install
compile the PHP docs. It still compiles with DocBook 3.0, as well.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@14693 c90b9560-bf6c-de11-be94-00142212c4b1
1999-10-20 22:41:42 +00:00

216 lines
6 KiB
Text

<reference id="ref.mhash">
<title>Hash functions</title>
<titleabbrev>mhash</titleabbrev>
<partintro>
<para>
These functions are intended to work with <ulink url="&url.mhash;">mhash</ulink>.</para>
<para>
This is an interface to the mhash library. mhash supports a wide variety of
hash algorithms such as MD5, SHA1, GOST, and many others.</para>
<para>
To use it, download the mhash distribution from <ulink url="&url.mhash;">its web site</ulink> and follow the included
installation instructions. You need to compile PHP with the <option role="configure">--with-mhash</option> parameter to enable this
extension.</para>
<para>
mhash can be used to create checksums, message digests, and more.</para>
<para>
<example>
<title>Compute the SHA1 key and print it out as hex</title>
<programlisting role="php">
&lt;?php
$input = "Let us meet at 9 o' clock at the secret place.";
$hash = mhash(MHASH_SHA1, $input);
print "The hash is ".bin2hex($hash)."\n";
?&gt;
</programlisting>
</example>
This will produce:
<programlisting>
The hash is d3b85d710d8f6e4e5efd4d5e67d041f9cecedafe
</programlisting>
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 HAVAL you use the PHP constant
MHASH_HAVAL.</para>
<para>
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.
<itemizedlist>
<listitem><simpara>
MHASH_MD5</simpara></listitem>
<listitem><simpara>
MHASH_SHA1</simpara></listitem>
<listitem><simpara>
MHASH_HAVAL</simpara></listitem>
<listitem><simpara>
MHASH_RIPEMD160</simpara></listitem>
<listitem><simpara>
MHASH_RIPEMD128</simpara></listitem>
<listitem><simpara>
MHASH_SNEFRU</simpara></listitem>
<listitem><simpara>
MHASH_TIGER</simpara></listitem>
<listitem><simpara>
MHASH_GOST</simpara></listitem>
<listitem><simpara>
MHASH_CRC32</simpara></listitem>
<listitem><simpara>
MHASH_CRC32B</simpara></listitem>
</itemizedlist></para>
</partintro>
<refentry id="function.mhash-get-hash-name">
<refnamediv>
<refname>mhash_get_hash_name</refname>
<refpurpose>Get the name of the specified hash</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>mhash_get_hash_name</function></funcdef>
<paramdef>int <parameter>hash</parameter></paramdef>
</funcsynopsis>
<para>
<function>mhash_get_hash_name</function> is used to get the name of the
specified hash.</para>
<para>
<function>mhash_get_hash_name</function> takes the hash id as an argument
and returns the name of the hash or false, if the hash does not exist.</para>
<para>
<example>
<title>mhash_get_hash_name example</title>
<programlisting>
&lt;?php
$hash = MHASH_MD5;
print mhash_get_hash_name($hash);
?&gt;
</programlisting>
</example>
The above example will print out:
<programlisting>
MD5
</programlisting></para>
</refsect1>
</refentry>
<refentry id="function.mhash-get-block-size">
<refnamediv>
<refname>mhash_get_block_size</refname>
<refpurpose>Get the block size of the specified hash</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>mhash_get_block_size</function></funcdef>
<paramdef>int <parameter>hash</parameter></paramdef>
</funcsynopsis>
<para>
<function>mhash_get_block_size</function> is used to get the size of a
block of the specified <parameter>hash</parameter>.</para>
<para>
<function>mhash_get_block_size</function> takes one argument, the
<parameter>hash</parameter> and returns the size in bytes or false, if
the <parameter>hash</parameter> does not exist.</para>
</refsect1>
</refentry>
<refentry id="function.mhash-count">
<refnamediv>
<refname>mhash_count</refname>
<refpurpose>Get the highest available hash id</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>mhash_count</function></funcdef>
<paramdef>void </paramdef>
</funcsynopsis>
<para>
<function>mhash_count</function> returns the highest available hash
id. Hashes are numbered from 0 to this hash id.</para>
<para>
<example>
<title>Traversing all hashes</title>
<programlisting>
&lt;?php
$nr = mhash_count();
for($i = 0; $i &lt;= $nr; $i++) {
echo sprintf("The blocksize of %s is %d\n",
mhash_get_hash_name($i),
mhash_get_block_size($i));
}
?&gt;
</programlisting>
</example></para>
</refsect1>
</refentry>
<refentry id="function.mhash">
<refnamediv>
<refname>mhash</refname>
<refpurpose>Compute hash</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>mhash</function></funcdef>
<paramdef>int <parameter>hash</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
</funcsynopsis>
<para>
<function>mhash</function> applies a hash function specified by
<parameter>hash</parameter> to the <parameter>data</parameter> and
returns the resulting hash (also called digest).</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->