uTools-Manuals/docs/php/hash_init.html
2019-04-28 19:00:34 +08:00

158 lines
6.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>初始化增量哈希运算上下文</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.hash-init" class="refentry">
<div class="refnamediv">
<h1 class="refname">hash_init</h1>
<p class="verinfo">(PHP 5 &gt;= 5.1.2, PHP 7, PECL hash &gt;= 1.1)</p><p class="refpurpose"><span class="refname">hash_init</span> &mdash; <span class="dc-title">初始化增量哈希运算上下文</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.hash-init-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>hash_init</strong></span>
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$algo</code></span>
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = 0</span></span>
[, <span class="methodparam"><span class="type">string</span> <code class="parameter">$key</code><span class="initializer"> = <strong><code>NULL</code></strong></span></span>
]] ) : <span class="type"><span class="type HashContext">HashContext</span></span></div>
</div>
<div class="refsect1 parameters" id="refsect1-function.hash-init-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">algo</code></dt>
<dd>
<p class="para">
要使用的哈希算法名称,例如:&quot;md5&quot;&quot;sha256&quot;&quot;haval160,4&quot; 等。
如何获取受支持的算法清单,请参见 <span class="function"><a href="hash_algos.html" class="function">hash_algos()</a></span>
</p>
</dd>
<dt>
<code class="parameter">options</code></dt>
<dd>
<p class="para">
进行哈希运算的可选设置,目前仅支持一个选项:<strong><code>HASH_HMAC</code></strong>
当指定此选项的时候,<em class="emphasis">必须</em> 指定 <code class="parameter">key</code> 参数。
</p>
</dd>
<dt>
<code class="parameter">key</code></dt>
<dd>
<p class="para">
<code class="parameter">options</code> 参数为 <strong><code>HASH_HMAC</code></strong> 时,
使用此参数传入进行 HMAC 哈希运算时的共享密钥。
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.hash-init-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
返回哈希运算上下文对象,以供
<span class="function"><a href="hash_update.html" class="function">hash_update()</a></span>
<span class="function"><a href="hash_update_stream.html" class="function">hash_update_stream()</a></span><span class="function"><a href="hash_update_file.html" class="function">hash_update_file()</a></span>,
<span class="function"><a href="hash_final.html" class="function">hash_final()</a></span> 函数使用。
</p>
</div>
<div class="refsect1 changelog" id="refsect1-function.hash-init-changelog">
<h3 class="title">更新日志</h3>
<p class="para">
<table class="doctable informaltable">
<thead>
<tr>
<th>版本</th>
<th>说明</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td>7.2.0</td>
<td>当使用 <strong><code>HASH_HMAC</code></strong> 选项的时候不再支持非加密的哈希函数adler32crc32crc32bfnv132fnv1a32fnv164fnv1a64joaat</td>
</tr>
<tr>
<td>7.2.0</td>
<td>
返回 <strong class="classname">HashContext</strong> 对象,不再返回资源类型。
</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.hash-init-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="zlib-encode.example.basic">
<p><strong>Example #1 增量哈希运算例程</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$ctx&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">hash_init</span><span style="color: #007700">(</span><span style="color: #DD0000">'md5'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">hash_update</span><span style="color: #007700">(</span><span style="color: #0000BB">$ctx</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'The&nbsp;quick&nbsp;brown&nbsp;fox&nbsp;'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">hash_update</span><span style="color: #007700">(</span><span style="color: #0000BB">$ctx</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'jumped&nbsp;over&nbsp;the&nbsp;lazy&nbsp;dog.'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">hash_final</span><span style="color: #007700">(</span><span style="color: #0000BB">$ctx</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程会输出:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
5c6ffbdd40d9556b73a21e63c3e0e904
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.hash-init-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="hash.html" class="function" rel="rdfs-seeAlso">hash()</a> - 生成哈希值 (消息摘要)</span></li>
<li class="member"><span class="function"><a href="hash_algos.html" class="function" rel="rdfs-seeAlso">hash_algos()</a> - 返回已注册的哈希算法列表</span></li>
<li class="member"><span class="function"><a href="hash_file.html" class="function" rel="rdfs-seeAlso">hash_file()</a> - 使用给定文件的内容生成哈希值</span></li>
<li class="member"><span class="function"><a href="hash_hmac.html" class="function" rel="rdfs-seeAlso">hash_hmac()</a> - 使用 HMAC 方法生成带有密钥的哈希值</span></li>
<li class="member"><span class="function"><a href="hash_hmac_file.html" class="function" rel="rdfs-seeAlso">hash_hmac_file()</a> - 使用 HMAC 方法和给定文件的内容生成带密钥的哈希值</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>