2019-04-28 19:00:34 +08:00

118 lines
5.1 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>计算字符串的 MD5 散列值</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.md5" class="refentry">
<div class="refnamediv">
<h1 class="refname">md5</h1>
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">md5</span> &mdash; <span class="dc-title">计算字符串的 MD5 散列值</span></p>
</div>
<div id="function.md5-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.md5-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>md5</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"> = <strong><code>FALSE</code></strong></span></span>
] ) : <span class="type">string</span></div>
<p class="para rdfs-comment">
使用 <a href="http://www.faqs.org/rfcs/rfc1321" class="link external">&raquo;&nbsp;RSA 数据安全公司的 MD5 报文算法</a>计算 <code class="parameter">str</code> 的 MD5 散列值。
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.md5-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>,那么 MD5 报文摘要将以16字节长度的原始二进制格式返回。
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.md5-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
以 32 字符十六进制数字形式返回散列值。
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.md5-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-5921">
<p><strong>Example #1 <span class="function"><strong>md5()</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">md5</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">)&nbsp;===&nbsp;</span><span style="color: #DD0000">'1f3870be274f6c49b3e31a0c6728957f'</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.md5-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="md5_file.html" class="function" rel="rdfs-seeAlso">md5_file()</a> - 计算指定文件的 MD5 散列值</span></li>
<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="sha1.html" class="function" rel="rdfs-seeAlso">sha1()</a> - 计算字符串的 sha1 散列值</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>