<?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 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.hash-init.php',
    1 => 'hash_init',
    2 => 'Initialise un contexte de hachage incr&eacute;mental',
  ),
  'up' => 
  array (
    0 => 'ref.hash.php',
    1 => 'hash_pbkdf2',
  ),
  'prev' => 
  array (
    0 => 'function.hash-hmac-file.php',
    1 => 'hash_hmac_file',
  ),
  'next' => 
  array (
    0 => 'function.hash-update.php',
    1 => 'hash_update',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    '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">Initialise un contexte de hachage incrémental</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.hash-init-description">
  <h3 class="title">Description</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">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">algo</code></dt>
     <dd>
      <p class="para">
       Nom de l&#039;algorithme de hachage sélectionné (par exemple : <code class="literal">&quot;sha256&quot;</code>).
       Pour une liste des algorithmes supportés voir <span class="function"><a href="function.hash-algos.php" class="function">hash_algos()</a></span>.
       <blockquote class="note"><p><strong class="note">Note</strong>: 
        <p class="para">
         Les fonctions de hachage non cryptographiques ne sont pas autorisées si le drapeau <strong><code><a href="hash.constants.php#constant.hash-hmac">HASH_HMAC</a></code></strong>
         est spécifié.
        </p>
       </p></blockquote>
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       Configurations optionnelles pour la génération du hachage, supporte
       actuellement seulement une option :
       <strong><code><a href="hash.constants.php#constant.hash-hmac">HASH_HMAC</a></code></strong>. Lorsque cette option est spécifiée, le paramètre
       <code class="parameter">key</code> <em>doit</em> être spécifié.
      </p>
     </dd>
    
    
     <dt><code class="parameter">key</code></dt>
     <dd>
      <p class="para">
       Lorsque <strong><code><a href="hash.constants.php#constant.hash-hmac">HASH_HMAC</a></code></strong> est spécifiée pour <code class="parameter">flags</code>,
       une clé secrète partagée qui sera utilisée avec la méthode de hachage
       HMAC doit être fournie dans ce paramètre.
      </p>
     </dd>
    
    
     <dt><code class="parameter">options</code></dt>
     <dd>
      <p class="para">
       Un tableau d&#039;options pour les divers algorithmes de hachage.
       Actuellement, seul le paramètre <code class="parameter">&quot;seed&quot;</code> est
       supporté pour les variantes MurmurHash.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.hash-init-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne le contexte de hachage HashContext pour utilisation avec
   <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> et <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">Erreurs / Exceptions</h3>
  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     Lève une exception <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> si le
     <code class="parameter">algo</code> est inconnu, s&#039;il s&#039;agit d&#039;une fonction de
     hachage non cryptographique, ou si <code class="parameter">key</code> est vide.
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     Passer des options de configuration de type incorrect dans
     <code class="parameter">options</code> émettra désormais une erreur
     <strong><code><a href="errorfunc.constants.php#constant.e-deprecated">E_DEPRECATED</a></code></strong>, car elles peuvent être mal interprétées.
     Cela entraînera une exception <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> à
     l&#039;avenir.
    </span>
   </li>
  </ul>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.hash-init-changelog">
  <h3 class="title">Historique</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.4.0</td>
       <td>Passer des options d&#039;un type incorrect est désormais déconseillé.</td>
      </tr>

      <tr>
       <td>8.1.0</td>
       <td>Le paramètre <code class="parameter">options</code> a été ajouté.</td>
      </tr>

      <tr>
       <td>7.2.0</td>
       <td>L&#039;usage de fonction de hachage non-cryptographique (adler32, crc32, crc32b, fnv132, fnv1a32, fnv164, fnv1a64, joaat) avec <strong><code><a href="hash.constants.php#constant.hash-hmac">HASH_HMAC</a></code></strong> a été désactivé.</td>
      </tr>

      <tr>
       <td>8.0.0</td>
       <td>
        Lève une exception <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> dorénavant si le
        paramètre <code class="parameter">algo</code> est inconnu ou n&#039;est pas
        une fonction de hachage cryptographique, ou si le paramètre
        <code class="parameter">key</code> est vide.
        Précédemment, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> était retourné et un message
        <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> était émis.
       </td>
      </tr>

      <tr>
       <td>7.2.0</td>
       <td>
        Retourne une <span class="classname"><a href="class.hashcontext.php" class="classname">HashContext</a></span> au lieu d&#039;une ressource.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.hash-init-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple de hachage incrémental</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>L&#039;exemple ci-dessus va afficher :</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">Voir aussi</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> - Retourne une liste des algorithmes de hachage enregistr&eacute;s</span></li>
    <li><span class="function"><a href="function.hash-update.php" class="function" rel="rdfs-seeAlso">hash_update()</a> - Ajoute des donn&eacute;es dans le contexte de hachage actif</span></li>
    <li><span class="function"><a href="function.hash-update-file.php" class="function" rel="rdfs-seeAlso">hash_update_file()</a> - Ajoute des donn&eacute;es dans un contexte de hachage actif provenant d'un fichier</span></li>
    <li><span class="function"><a href="function.hash-update-stream.php" class="function" rel="rdfs-seeAlso">hash_update_stream()</a> - Ajoute des donn&eacute;es dans un contexte de hachage actif d'un flux ouvert</span></li>
    <li><span class="function"><a href="function.hash-final.php" class="function" rel="rdfs-seeAlso">hash_final()</a> - Finalise un hachage incr&eacute;mental et retourne le r&eacute;sultat de l'empreinte num&eacute;rique</span></li>
   </ul>
  </p>
 </div>


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