mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
185 lines
6.9 KiB
HTML
185 lines
6.9 KiB
HTML
<!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.mcrypt-create-iv" class="refentry">
|
||
<div class="refnamediv">
|
||
<h1 class="refname">mcrypt_create_iv</h1>
|
||
<p class="verinfo">(PHP 4, PHP 5, PHP 7 < 7.2.0, PECL mcrypt >= 1.0.0)</p><p class="refpurpose"><span class="refname">mcrypt_create_iv</span> — <span class="dc-title">从随机源创建初始向量</span></p>
|
||
|
||
</div>
|
||
|
||
<div id="function.mcrypt-create-iv-refsynopsisdiv">
|
||
<div class="warning"><strong class="warning">Warning</strong>
|
||
|
||
<p class="para">
|
||
This function was <em class="emphasis">DEPRECATED</em> in PHP 7.1.0, and
|
||
<em class="emphasis">REMOVED</em> in PHP 7.2.0.
|
||
</p>
|
||
<p class="para">
|
||
Alternatives to this function include:
|
||
</p>
|
||
|
||
<ul class="simplelist">
|
||
<li class="member"><span class="function"><a href="random_bytes.html" class="function">random_bytes()</a></span></li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="refsect1 description" id="refsect1-function.mcrypt-create-iv-description">
|
||
<h3 class="title">说明</h3>
|
||
<div class="methodsynopsis dc-description">
|
||
<span class="methodname"><strong>mcrypt_create_iv</strong></span>
|
||
( <span class="methodparam"><span class="type">int</span> <code class="parameter">$size</code></span>
|
||
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$source</code><span class="initializer"> = MCRYPT_DEV_URANDOM</span></span>
|
||
] ) : <span class="type">string</span></div>
|
||
|
||
<p class="para rdfs-comment">
|
||
从随机源创建初始向量。
|
||
</p>
|
||
<p class="para">
|
||
初始向量只是为了给加密算法提供一个可用的种子,
|
||
所以它不需要安全保护,
|
||
你甚至可以随同密文一起发布初始向量也不会对安全性带来影响。
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 parameters" id="refsect1-function.mcrypt-create-iv-parameters">
|
||
<h3 class="title">参数</h3>
|
||
<p class="para">
|
||
<dl>
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">size</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
初始向量大小。
|
||
</p>
|
||
</dd>
|
||
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">source</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
初始向量数据来源。可选值有:
|
||
<strong><code>MCRYPT_RAND</code></strong> (系统随机数生成器),
|
||
<strong><code>MCRYPT_DEV_RANDOM</code></strong> (从
|
||
<var class="filename">/dev/random</var> 文件读取数据) 和
|
||
<strong><code>MCRYPT_DEV_URANDOM</code></strong> (从
|
||
<var class="filename">/dev/urandom</var> 文件读取数据)。
|
||
在 Windows 平台,PHP 5.3.0 之前的版本中,仅支持 <strong><code>MCRYPT_RAND</code></strong>。
|
||
</p>
|
||
<p class="para">
|
||
请注意,在 PHP 5.6.0 之前的版本中,
|
||
此参数的默认值为 <strong><code>MCRYPT_DEV_RANDOM</code></strong>。
|
||
</p>
|
||
<blockquote class="note"><p><strong class="note">Note</strong>:
|
||
<span class="simpara">
|
||
需要注意的是,如果没有更多可用的用来产生随机数据的信息,那么
|
||
<strong><code>MCRYPT_DEV_RANDOM</code></strong> 可能进入阻塞状态。
|
||
</span>
|
||
</p></blockquote>
|
||
</dd>
|
||
|
||
|
||
</dl>
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 returnvalues" id="refsect1-function.mcrypt-create-iv-returnvalues">
|
||
<h3 class="title">返回值</h3>
|
||
<p class="para">
|
||
返回初始向量。如果发生错误,则返回 <strong><code>FALSE</code></strong>。
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 changelog" id="refsect1-function.mcrypt-create-iv-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>5.6.0</td>
|
||
<td>
|
||
<code class="parameter">source</code> 参数的默认值是
|
||
<strong><code>MCRYPT_DEV_URANDOM</code></strong>。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td>5.3.0</td>
|
||
<td>
|
||
<strong><code>MCRYPT_DEV_RANDOM</code></strong> 和
|
||
<strong><code>MCRYPT_DEV_URANDOM</code></strong> 在 Windows 平台也可用了。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td>5.3.0</td>
|
||
<td>
|
||
不再需要提前调用 <span class="function"><a href="srand.html" class="function">srand()</a></span> 函数,
|
||
由本函数自动完成调用。
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 examples" id="refsect1-function.mcrypt-create-iv-examples">
|
||
<h3 class="title">范例</h3>
|
||
<p class="para">
|
||
<div class="example" id="foobar.examples.basic">
|
||
<p><strong>Example #1 <span class="function"><strong>mcrypt_create_iv()</strong></span> 例程</strong></p>
|
||
<div class="example-contents">
|
||
<div class="phpcode"><pre><span style="color: #000000">
|
||
<span style="color: #0000BB"><?php<br /> $size </span><span style="color: #007700">= </span><span style="color: #0000BB">mcrypt_get_iv_size</span><span style="color: #007700">(</span><span style="color: #0000BB">MCRYPT_CAST_256</span><span style="color: #007700">, </span><span style="color: #0000BB">MCRYPT_MODE_CFB</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$iv </span><span style="color: #007700">= </span><span style="color: #0000BB">mcrypt_create_iv</span><span style="color: #007700">(</span><span style="color: #0000BB">$size</span><span style="color: #007700">, </span><span style="color: #0000BB">MCRYPT_DEV_RANDOM</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
|
||
</span>
|
||
</pre></div>
|
||
</div>
|
||
|
||
</div>
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 seealso" id="refsect1-function.mcrypt-create-iv-seealso">
|
||
<h3 class="title">参见</h3>
|
||
<p class="para">
|
||
<ul class="simplelist">
|
||
<li class="member"><a href="http://www.ciphersbyritter.com/GLOSSARY.HTM#IV" class="link external">» http://www.ciphersbyritter.com/GLOSSARY.HTM#IV</a></li>
|
||
<li class="member"><a href="http://www.quadibloc.com/crypto/co0409.htm" class="link external">» http://www.quadibloc.com/crypto/co0409.htm</a></li>
|
||
<li class="member">Applied Cryptography by Schneier (ISBN 0-471-11709-9) 9.3 节。</li>
|
||
<li class="member"><span class="function"><a href="random_bytes.html" class="function" rel="rdfs-seeAlso">random_bytes()</a> - Generates cryptographically secure pseudo-random bytes</span></li>
|
||
</ul>
|
||
</p>
|
||
</div>
|
||
|
||
</div></div></div></body></html> |