mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@9477 c90b9560-bf6c-de11-be94-00142212c4b1
217 lines
5.5 KiB
Text
217 lines
5.5 KiB
Text
<reference id="ref.mhash">
|
|
<title>mhash functions</title>
|
|
<titleabbrev>mhash</titleabbrev>
|
|
|
|
<partintro>
|
|
<para>
|
|
These functions are intended to work with <ulink
|
|
url="&url.mhash;">mhash</ulink>.
|
|
|
|
<para>
|
|
This is an interface to the mhash library. mhash supports a wide area of
|
|
hash algorithms such as MD5, SHA1, GOST and many others.
|
|
|
|
<para>
|
|
To use it, download mhash-x.x.x.tar.gz from <ulink
|
|
url="&url.mhash;">here</ulink> and follow the included installation
|
|
instructions. You need to compile PHP with the --with-mhash parameter to
|
|
enable this extension.
|
|
|
|
<para>
|
|
mhash can be used to create checksums, message digests and more.
|
|
|
|
<para>
|
|
<example>
|
|
<title>Compute the SHA1 key and print it out as hex</title>
|
|
<programlisting role="php">
|
|
<?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";
|
|
|
|
?>
|
|
</programlisting>
|
|
</example>
|
|
|
|
This will produce:
|
|
|
|
<programlisting>
|
|
The hash is d3b85d710d8f6e4e5efd4d5e67d041f9cecedafe
|
|
</programlisting>
|
|
|
|
For a complete list of supported hashes, see the documentation of mhash.
|
|
The general rule is that you can access the hash from PHP with
|
|
MHASH_HASHNAME.
|
|
|
|
<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
|
|
<listitem><simpara>
|
|
MHASH_SHA1
|
|
<listitem><simpara>
|
|
MHASH_HAVAL
|
|
<listitem><simpara>
|
|
MHASH_RIPEMD160
|
|
<listitem><simpara>
|
|
MHASH_RIPEMD128
|
|
<listitem><simpara>
|
|
MHASH_SNEFRU
|
|
<listitem><simpara>
|
|
MHASH_TIGER
|
|
<listitem><simpara>
|
|
MHASH_GOST
|
|
<listitem><simpara>
|
|
MHASH_CRC32
|
|
<listitem><simpara>
|
|
MHASH_CRC32B
|
|
|
|
</itemizedlist>
|
|
|
|
</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>
|
|
<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>
|
|
<example>
|
|
<title>mhash_get_hash_name example</title>
|
|
<programlisting>
|
|
<?php
|
|
$hash = MHASH_MD5;
|
|
|
|
print mhash_get_hash_name($hash);
|
|
?>
|
|
</programlisting>
|
|
</example>
|
|
|
|
The above example will print out:
|
|
<programlisting>
|
|
MD5
|
|
</programlisting>
|
|
|
|
</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>
|
|
<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.
|
|
|
|
</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></paramdef>
|
|
</funcsynopsis>
|
|
|
|
<para>
|
|
<function>mhash_count</function> returns the highest available hash
|
|
id. Hashes are numbered from 0 to this hash id.
|
|
|
|
<para>
|
|
<example>
|
|
<title>Traversing all hashes</title>
|
|
<programlisting>
|
|
<?php
|
|
|
|
$nr = mhash_count();
|
|
|
|
for($i = 0; $i <= $nr; $i++) {
|
|
echo sprintf("The blocksize of %s is %d\n",
|
|
mhash_get_hash_name($i),
|
|
mhash_get_block_size($i));
|
|
}
|
|
?>
|
|
</programlisting>
|
|
</example>
|
|
|
|
</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).
|
|
|
|
</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:
|
|
-->
|