<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.hash.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.hash-init.php',
    1 => 'hash_init',
    2 => 'Initialize an incremental hashing context',
  ),
  'up' => 
  array (
    0 => 'ref.hash.php',
    1 => 'Hash Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.hash-hmac-file.php',
    1 => 'hash_hmac_file',
  ),
  'next' => 
  array (
    0 => 'function.hash-pbkdf2.php',
    1 => 'hash_pbkdf2',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/hash/functions/hash-init.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.hash-init" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">hash_init</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.2, PHP 7, PHP 8, PECL hash &gt;= 1.1)</p><p class="refpurpose"><span class="refname">hash_init</span> &mdash; <span class="dc-title">Initialize an incremental hashing context</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.hash-init-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>hash_init</strong></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">$algo</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">$flags</code><span class="initializer"> = 0</span></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 class="initializer"> = &quot;&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$options</code><span class="initializer"> = []</span></span><br>): <span class="type"><a href="class.hashcontext.php" class="type HashContext">HashContext</a></span></div>


 </div>

 <div class="refsect1 parameters" id="refsect1-function.hash-init-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">algo</code></dt>
     <dd>
      <p class="para">
       Name of selected hashing algorithm (e.g. <code class="literal">&quot;sha256&quot;</code>).
       For a list of supported algorithms see <span class="function"><a href="function.hash-algos.php" class="function">hash_algos()</a></span>.
       <blockquote class="note"><p><strong class="note">Nota</strong>: 
        <p class="para">
         Non-cryptographic hash functions are not allowed if the <strong><code><a href="hash.constants.php#constant.hash-hmac">HASH_HMAC</a></code></strong>
         flag is specified.
        </p>
       </p></blockquote>
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       Optional settings for hash generation, currently supports only one option:
       <strong><code><a href="hash.constants.php#constant.hash-hmac">HASH_HMAC</a></code></strong>.  When specified, the <code class="parameter">key</code>
       <em>must</em> be specified.
      </p>
     </dd>
    
    
     <dt><code class="parameter">key</code></dt>
     <dd>
      <p class="para">
       When <strong><code><a href="hash.constants.php#constant.hash-hmac">HASH_HMAC</a></code></strong> is specified for <code class="parameter">flags</code>,
       a shared secret key to be used with the HMAC hashing method must be supplied in this
       parameter.
      </p>
     </dd>
    
    
     <dt><code class="parameter">options</code></dt>
     <dd>
      <p class="para">
       An array of options for the various hashing algorithms.
       Currently, only the <code class="literal">&quot;seed&quot;</code> parameter is
       supported by the MurmurHash variants.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.hash-init-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Returns a Hashing Context for use with <span class="function"><a href="function.hash-update.php" class="function">hash_update()</a></span>,
   <span class="function"><a href="function.hash-update-stream.php" class="function">hash_update_stream()</a></span>, <span class="function"><a href="function.hash-update-file.php" class="function">hash_update_file()</a></span>,
   and <span class="function"><a href="function.hash-final.php" class="function">hash_final()</a></span>.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.hash-init-errors">
  <h3 class="title">Errori/Eccezioni</h3>
  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     Throws a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> exception if
     <code class="parameter">algo</code> is unknown or is a non-cryptographic hash
     function, or if <code class="parameter">key</code> is empty.
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     Passing configurations options of the wrong type in
     <code class="parameter">options</code> will now emit an
     <strong><code><a href="errorfunc.constants.php#constant.e-deprecated">E_DEPRECATED</a></code></strong> error because they can be interpreted
     incorrectly.
     This will become a <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> in the
     future.
    </span>
   </li>
  </ul>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.hash-init-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Versione</th>
       <th>Descrizione</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.4.0</td>
       <td>Passing options of a wrong type is now deprecated.</td>
      </tr>

      <tr>
       <td>8.1.0</td>
       <td>The <code class="parameter">options</code> parameter has been added.</td>
      </tr>

      <tr>
       <td>8.0.0</td>
       <td>
        Now throws an <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> exception if the
        <code class="parameter">algo</code> is unknown or is a non-cryptographic hash
        function, or if <code class="parameter">key</code> is empty. Previously,
        <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> was returned and an <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> message was
        emitted.
       </td>
      </tr>

      <tr>
       <td>7.2.0</td>
       <td>Usage of non-cryptographic hash functions (adler32, crc32, crc32b, fnv132, fnv1a32, fnv164, fnv1a64, joaat) with <strong><code><a href="hash.constants.php#constant.hash-hmac">HASH_HMAC</a></code></strong> was disabled.</td>
      </tr>

      <tr>
       <td>7.2.0</td>
       <td>
        Return <span class="classname"><a href="class.hashcontext.php" class="classname">HashContext</a></span> instead of resource.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.hash-init-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Incremental hashing example</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$hash </span><span style="color: #007700">= </span><span style="color: #0000BB">hash</span><span style="color: #007700">(</span><span style="color: #DD0000">'sha256'</span><span style="color: #007700">, </span><span style="color: #DD0000">'The quick brown fox jumped over the lazy dog.'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$ctx </span><span style="color: #007700">= </span><span style="color: #0000BB">hash_init</span><span style="color: #007700">(</span><span style="color: #DD0000">'sha256'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">hash_update</span><span style="color: #007700">(</span><span style="color: #0000BB">$ctx</span><span style="color: #007700">, </span><span style="color: #DD0000">'The quick brown fox '</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">hash_update</span><span style="color: #007700">(</span><span style="color: #0000BB">$ctx</span><span style="color: #007700">, </span><span style="color: #DD0000">'jumped over the lazy dog.'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$incremental_hash </span><span style="color: #007700">= </span><span style="color: #0000BB">hash_final</span><span style="color: #007700">(</span><span style="color: #0000BB">$ctx</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">$incremental_hash</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$hash </span><span style="color: #007700">=== </span><span style="color: #0000BB">$incremental_hash</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">68b1282b91de2c054c36629cb8dd447f12f096d3e3c587978dc2248444633483
bool(true)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.hash-init-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.hash-algos.php" class="function" rel="rdfs-seeAlso">hash_algos()</a> - Return a list of registered hashing algorithms</span></li>
    <li><span class="function"><a href="function.hash-update.php" class="function" rel="rdfs-seeAlso">hash_update()</a> - Pump data into an active hashing context</span></li>
    <li><span class="function"><a href="function.hash-update-file.php" class="function" rel="rdfs-seeAlso">hash_update_file()</a> - Pump data into an active hashing context from a file</span></li>
    <li><span class="function"><a href="function.hash-update-stream.php" class="function" rel="rdfs-seeAlso">hash_update_stream()</a> - Pump data into an active hashing context from an open stream</span></li>
    <li><span class="function"><a href="function.hash-final.php" class="function" rel="rdfs-seeAlso">hash_final()</a> - Finalize an incremental hash and return resulting digest</span></li>
   </ul>
  </p>
 </div>


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