uTools-Manuals/docs/php/sha1.html
2019-04-08 23:22:26 +08:00

119 lines
4.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>计算字符串的 sha1 散列值</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.sha1" class="refentry">
<div class="refnamediv">
<h1 class="refname">sha1</h1>
<p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">sha1</span> &mdash; <span class="dc-title">计算字符串的 sha1 散列值</span></p>
</div>
<div id="function.sha1-refsynopsisdiv">
<div class="warning"><strong class="warning">Warning</strong>
<p class="para">
It is not recommended to use this function to secure passwords,
due to the fast nature of this hashing algorithm. See the
<a href="faq.passwords.html#faq.passwords.fasthash" class="link">Password Hashing FAQ</a>
for details and best practices.
</p>
</div>
</div>
<div class="refsect1 description" id="refsect1-function.sha1-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>sha1</strong></span>
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></span>
[, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$raw_output</code><span class="initializer"> = false</span></span>
] ) : <span class="type">string</span></div>
<p class="simpara">
利用<a href="http://www.faqs.org/rfcs/rfc3174" class="link external">&raquo;&nbsp;美国安全散列算法 1</a> 计算字符串的 sha1 散列值。
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.sha1-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">str</code></dt>
<dd>
<p class="para">
输入字符串。
</p>
</dd>
<dt>
<code class="parameter">raw_output</code></dt>
<dd>
<p class="para">
如果可选的 <code class="parameter">raw_output</code> 参数被设置为 <strong><code>TRUE</code></strong>
那么 sha1 摘要将以 20 字符长度的原始格式返回,
否则返回值是一个 40 字符长度的十六进制数字。
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.sha1-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
返回 sha1 散列值字符串。
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.sha1-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-5938">
<p><strong>Example #1 <span class="function"><strong>sha1()</strong></span> 范例</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'apple'</span><span style="color: #007700">;<br /><br />if&nbsp;(</span><span style="color: #0000BB">sha1</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">)&nbsp;===&nbsp;</span><span style="color: #DD0000">'d0be2dc421be4fcd0172e5afceea3970e2f3d940'</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Would&nbsp;you&nbsp;like&nbsp;a&nbsp;green&nbsp;or&nbsp;red&nbsp;apple?"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.sha1-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="sha1_file.html" class="function" rel="rdfs-seeAlso">sha1_file()</a> - 计算文件的 sha1 散列值</span></li>
<li class="member"><span class="function"><a href="crc32.html" class="function" rel="rdfs-seeAlso">crc32()</a> - 计算一个字符串的 crc32 多项式</span></li>
<li class="member"><span class="function"><a href="md5.html" class="function" rel="rdfs-seeAlso">md5()</a> - 计算字符串的 MD5 散列值</span></li>
<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="crypt.html" class="function" rel="rdfs-seeAlso">crypt()</a> - 单向字符串散列</span></li>
<li class="member"><span class="function"><a href="password_hash.html" class="function" rel="rdfs-seeAlso">password_hash()</a> - 创建密码的散列hash</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>