<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.sodium.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.sodium-crypto-stream-xchacha20-xor-ic.php',
    1 => 'sodium_crypto_stream_xchacha20_xor_ic',
    2 => 'Encrypts a message using a nonce and a secret key (no authentication)',
  ),
  'up' => 
  array (
    0 => 'ref.sodium.php',
    1 => 'Sodium 函数',
  ),
  'prev' => 
  array (
    0 => 'function.sodium-crypto-stream-xchacha20-xor.php',
    1 => 'sodium_crypto_stream_xchacha20_xor',
  ),
  'next' => 
  array (
    0 => 'function.sodium-crypto-stream-xor.php',
    1 => 'sodium_crypto_stream_xor',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/sodium/functions/sodium-crypto-stream-xchacha20-xor-ic.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.sodium-crypto-stream-xchacha20-xor-ic" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sodium_crypto_stream_xchacha20_xor_ic</h1>
  <p class="verinfo">(PHP 8 &gt;= 8.2.0)</p><p class="refpurpose"><span class="refname">sodium_crypto_stream_xchacha20_xor_ic</span> &mdash; <span class="dc-title">Encrypts a message using a nonce and a secret key (no authentication)</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.sodium-crypto-stream-xchacha20-xor-ic-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>sodium_crypto_stream_xchacha20_xor_ic</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="attribute"><a href="class.sensitiveparameter.php">#[\SensitiveParameter]</a> </span><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$message</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$nonce</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$counter</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="attribute"><a href="class.sensitiveparameter.php">#[\SensitiveParameter]</a> </span><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$key</code></span><br>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="simpara">
   The function is similar to <span class="function"><a href="function.sodium-crypto-stream-xchacha20-xor.php" class="function">sodium_crypto_stream_xchacha20_xor()</a></span>
   but adds the ability to set the initial value of the block counter to a non-zero value.
   This permits direct access to any block without having to compute the previous ones.
  </p>

  <div class="caution"><strong class="caution">警告</strong>
   <p class="simpara">
    This encryption is unauthenticated, and does not prevent chosen-ciphertext attacks.
    Make sure to combine the ciphertext with a Message Authentication Code,
    for example with <span class="function"><a href="function.sodium-crypto-aead-xchacha20poly1305-ietf-encrypt.php" class="function">sodium_crypto_aead_xchacha20poly1305_ietf_encrypt()</a></span> function,
    or <span class="function"><a href="function.sodium-crypto-auth.php" class="function">sodium_crypto_auth()</a></span>.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.sodium-crypto-stream-xchacha20-xor-ic-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt><code class="parameter">message</code></dt>
    <dd>
     <span class="simpara">
      The message to encrypt.
     </span>
    </dd>
   
   
    <dt><code class="parameter">nonce</code></dt>
    <dd>
     <span class="simpara">
      24-byte nonce.
     </span>
    </dd>
   
   
    <dt><code class="parameter">counter</code></dt>
    <dd>
     <span class="simpara">
      The initial value of the block counter.
     </span>
    </dd>
   
   
    <dt><code class="parameter">key</code></dt>
    <dd>
     <span class="simpara">
      Key, possibly generated from <span class="function"><a href="function.sodium-crypto-stream-xchacha20-keygen.php" class="function">sodium_crypto_stream_xchacha20_keygen()</a></span>.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sodium-crypto-stream-xchacha20-xor-ic-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="simpara">
   Encrypted message,  或者在失败时返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.sodium-crypto-stream-xchacha20-xor-ic-examples">
  <h3 class="title">示例</h3>
  <div class="example" id="example-1">
   <p><strong>示例 #1 <span class="function"><strong>sodium_crypto_stream_xchacha20_xor_ic()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$n2 </span><span style="color: #007700">= </span><span style="color: #0000BB">random_bytes</span><span style="color: #007700">(</span><span style="color: #0000BB">SODIUM_CRYPTO_STREAM_XCHACHA20_NONCEBYTES</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$left  </span><span style="color: #007700">= </span><span style="color: #0000BB">str_repeat</span><span style="color: #007700">(</span><span style="color: #DD0000">"\x01"</span><span style="color: #007700">, </span><span style="color: #0000BB">64</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$right </span><span style="color: #007700">= </span><span style="color: #0000BB">str_repeat</span><span style="color: #007700">(</span><span style="color: #DD0000">"\xfe"</span><span style="color: #007700">, </span><span style="color: #0000BB">64</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// All at once:<br /></span><span style="color: #0000BB">$stream7_unified </span><span style="color: #007700">= </span><span style="color: #0000BB">sodium_crypto_stream_xchacha20_xor</span><span style="color: #007700">(</span><span style="color: #0000BB">$left </span><span style="color: #007700">. </span><span style="color: #0000BB">$right</span><span style="color: #007700">, </span><span style="color: #0000BB">$n2</span><span style="color: #007700">, </span><span style="color: #0000BB">$key</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Piecewise, with initial counter:<br /></span><span style="color: #0000BB">$stream7_left  </span><span style="color: #007700">= </span><span style="color: #0000BB">sodium_crypto_stream_xchacha20_xor_ic</span><span style="color: #007700">(</span><span style="color: #0000BB">$left</span><span style="color: #007700">, </span><span style="color: #0000BB">$n2</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">$key</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stream7_right </span><span style="color: #007700">= </span><span style="color: #0000BB">sodium_crypto_stream_xchacha20_xor_ic</span><span style="color: #007700">(</span><span style="color: #0000BB">$right</span><span style="color: #007700">, </span><span style="color: #0000BB">$n2</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">$key</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stream7_concat </span><span style="color: #007700">= </span><span style="color: #0000BB">$stream7_left </span><span style="color: #007700">. </span><span style="color: #0000BB">$stream7_right</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream7_concat</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream7_unified </span><span style="color: #007700">=== </span><span style="color: #0000BB">$stream7_concat</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>以上示例的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">int(128)
bool(true)</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.sodium-crypto-stream-xchacha20-xor-ic-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.sodium-crypto-stream-xchacha20-xor.php" class="function" rel="rdfs-seeAlso">sodium_crypto_stream_xchacha20_xor()</a> - Encrypts a message using a nonce and a secret key (no authentication)</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>