<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/refs.crypto.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'book.hash.php',
    1 => 'Hash',
    2 => '散列消息摘要框架',
  ),
  'up' => 
  array (
    0 => 'refs.crypto.php',
    1 => '加密扩展',
  ),
  'prev' => 
  array (
    0 => 'refs.crypto.php',
    1 => '加密扩展',
  ),
  'next' => 
  array (
    0 => 'hash.setup.php',
    1 => '安装/配置',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/hash/book.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/book.hash.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="book.hash" class="book">
 
 <h1 class="title">散列消息摘要框架</h1>
 
 
 
 <div id="intro.hash" class="preface">
  <h1 class="title">简介</h1>
  <p class="para">
   该扩展提供了一些函数，可用于使用多种散列算法对任意长度的消息进行直接或增量处理，包括生成
   <abbr title="Hash-based Message Authentication Code">HMAC</abbr> 值以及包括 <abbr title="HMAC Key Definition Function">HKDF</abbr> 和
   <abbr title="Password-Based Key Derivation Function 2">PBKDF2</abbr> 在内的密钥派生。
  </p>
  <p class="para">
   散列算法大致分为三类，完整算法列表可在 <span class="function"><a href="function.hash-algos.php" class="function">hash_algos()</a></span> 的文档中找到。

   <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">
      校验和算法（例如 <code class="literal">&quot;crc32b&quot;</code> 或 <code class="literal">&quot;adler32&quot;</code>）：用于计算校验和，适用于检测传输错误等场景。这类算法通常速度非常快。但其生成的值往往容易被“猜测”或操纵以制造冲突，因此完全不适合用于加密用途。
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      非加密算法（例如 xxHash 系列）：这些算法通常用于计算散列表的散列值，因为它们旨在为任意字符串输入提供良好的分布性。这些算法通常速度较快，但同样不适合用于加密用途。
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      加密算法（例如 SHA-2 系列）：这些算法旨在生成能够反映输入特征但不可猜测且不易发生冲突的散列值。性能通常是次要考虑因素，但现代硬件通常对这些算法提供专门支持，在可用时 PHP 会尝试利用这些支持。
     </span>
     <span class="simpara">
      NIST（美国国家标准与技术研究院）的计算机安全资源中心提供了<a href="https://csrc.nist.gov/projects/hash-functions" class="link external">&raquo;&nbsp;关于美国联邦信息处理标准当前批准算法的说明</a>。
     </span>
     <div class="caution"><strong class="caution">警告</strong>
      <p class="para">
       一些早期的加密算法，例如 <code class="literal">&quot;md4&quot;</code>、<code class="literal">&quot;md5&quot;</code> 和
       <code class="literal">&quot;sha1&quot;</code>，已证明容易受到碰撞攻击，通常建议不再将其用于加密应用。
      </p>
     </div>
    </li>
   </ul>
  </p>

  <p class="para">
   另请参阅<a href="faq.passwords.php" class="link">关于安全密码散列的常见问题解答</a>，以获取在处理密码时使用散列函数的最佳实践信息。
  </p>
 </div>
 
 
 








 







 





 









<ul class="chunklist chunklist_book"><li><a href="hash.setup.php">安装/配置</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="hash.installation.php">安装</a></li><li><a href="hash.resources.php">资源类型</a></li></ul></li><li><a href="hash.constants.php">预定义常量</a></li><li><a href="class.hashcontext.php">HashContext</a> — HashContext 类<ul class="chunklist chunklist_book chunklist_children"><li><a href="hashcontext.construct.php">HashContext::__construct</a> — 私有构造方法以禁止直接实例化</li><li><a href="hashcontext.serialize.php">HashContext::__serialize</a> — 序列化 HashContext 对象</li><li><a href="hashcontext.unserialize.php">HashContext::__unserialize</a> — 反序列化 data 参数为 HashContext 对象</li></ul></li><li><a href="ref.hash.php">Hash 函数</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="function.hash.php">hash</a> — 生成散列值（消息摘要）</li><li><a href="function.hash-algos.php">hash_algos</a> — 返回已注册的散列算法列表</li><li><a href="function.hash-copy.php">hash_copy</a> — 拷贝哈希运算上下文</li><li><a href="function.hash-equals.php">hash_equals</a> — 可防止时序攻击的字符串比较</li><li><a href="function.hash-file.php">hash_file</a> — 给指定文件的内容生成散列值</li><li><a href="function.hash-final.php">hash_final</a> — 结束增量散列且返回摘要结果</li><li><a href="function.hash-hkdf.php">hash_hkdf</a> — Generate a HKDF key derivation of a supplied key input</li><li><a href="function.hash-hmac.php">hash_hmac</a> — 使用 HMAC 方法生成带有密钥的散列值</li><li><a href="function.hash-hmac-algos.php">hash_hmac_algos</a> — 返回适用于 hash_hmac 的已注册散列算法列表</li><li><a href="function.hash-hmac-file.php">hash_hmac_file</a> — 使用 HMAC 方法和给定文件的内容生成带密钥的散列值</li><li><a href="function.hash-init.php">hash_init</a> — 初始化增量散列运算上下文</li><li><a href="function.hash-pbkdf2.php">hash_pbkdf2</a> — 生成所提供密码的 PBKDF2 密钥导出</li><li><a href="function.hash-update.php">hash_update</a> — 向活跃的哈希运算上下文中填充数据</li><li><a href="function.hash-update-file.php">hash_update_file</a> — 从文件向活跃的散列运算上下文中填充数据</li><li><a href="function.hash-update-stream.php">hash_update_stream</a> — 从打开的流向活跃的散列运算上下文中填充数据</li></ul></li></ul></div><?php manual_footer($setup); ?>