<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.mcrypt.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.mdecrypt-generic.php',
    1 => 'mdecrypt_generic',
    2 => 'D&eacute;chiffre les donn&eacute;es',
  ),
  'up' => 
  array (
    0 => 'ref.mcrypt.php',
    1 => 'Fonctions Mcrypt',
  ),
  'prev' => 
  array (
    0 => 'function.mcrypt-module-self-test.php',
    1 => 'mcrypt_module_self_test',
  ),
  'next' => 
  array (
    0 => 'book.mhash.php',
    1 => 'Mhash',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/mcrypt/functions/mdecrypt-generic.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.mdecrypt-generic" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mdecrypt_generic</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.2, PHP 5, PHP 7 &lt; 7.2.0, PECL mcrypt &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">mdecrypt_generic</span> &mdash; <span class="dc-title">Déchiffre les données</span></p>

 </div>
 <div id="function.mdecrypt-generic-refsynopsisdiv">
  <div class="warning"><strong class="warning">Avertissement</strong><p class="simpara">
 Cette fonction est <em>OBSOLÈTE</em> à partir de PHP 7.1.0 et a été
 <em>SUPPRIMÉE</em> à partir de PHP 7.2.0.
 Dépendre de cette fonction est fortement déconseillé.
</p></div>
 </div>

 <div class="refsect1 description" id="refsect1-function.mdecrypt-generic-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mdecrypt_generic</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$td</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$data</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="simpara">
   Déchiffre les données <code class="parameter">data</code>. À noter que la longueur de
   la chaîne déchiffrée peut être plus longue que la chaîne originale, car elle
   peut avoir été complétée par des caractères.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mdecrypt-generic-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <dl>
   
    <dt><code class="parameter">td</code></dt>
    <dd>
     <span class="simpara">
      Un descripteur de chiffrement, retourné par la fonction
      <span class="function"><a href="function.mcrypt-module-open.php" class="function">mcrypt_module_open()</a></span>
     </span>
    </dd>
   
   
    <dt><code class="parameter">data</code></dt>
    <dd>
     <span class="simpara">
      Les données chiffrées.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mdecrypt-generic-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="simpara">
   Retourne la chaîne déchiffrée.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mdecrypt-generic-examples">
  <h3 class="title">Exemples</h3>
  <div class="example" id="example-1">
   <p><strong>Exemple #1 Exemple avec <span class="function"><strong>mdecrypt_generic()</strong></span></strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/* Données */<br /></span><span style="color: #0000BB">$key </span><span style="color: #007700">= </span><span style="color: #DD0000">'Ceci est une très longue clé de chiffrement, et même trop longue'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$plain_text </span><span style="color: #007700">= </span><span style="color: #DD0000">'Ceci sont des données importantes'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/* Ouvre le module et crée un VI */<br /></span><span style="color: #0000BB">$td </span><span style="color: #007700">= </span><span style="color: #0000BB">mcrypt_module_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'des'</span><span style="color: #007700">, </span><span style="color: #DD0000">''</span><span style="color: #007700">, </span><span style="color: #DD0000">'ecb'</span><span style="color: #007700">, </span><span style="color: #DD0000">''</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$key </span><span style="color: #007700">= </span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$key</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">mcrypt_enc_get_key_size</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$iv_size </span><span style="color: #007700">= </span><span style="color: #0000BB">mcrypt_enc_get_iv_size</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</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">$iv_size</span><span style="color: #007700">, </span><span style="color: #0000BB">MCRYPT_RAND</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Initialise le module de chiffrement */<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">mcrypt_generic_init</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">, </span><span style="color: #0000BB">$key</span><span style="color: #007700">, </span><span style="color: #0000BB">$iv</span><span style="color: #007700">) != -</span><span style="color: #0000BB">1</span><span style="color: #007700">) {<br /><br />    </span><span style="color: #FF8000">/* Chiffre les données */<br />    </span><span style="color: #0000BB">$c_t </span><span style="color: #007700">= </span><span style="color: #0000BB">mcrypt_generic</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">, </span><span style="color: #0000BB">$plain_text</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">mcrypt_generic_deinit</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">);<br /><br />    </span><span style="color: #FF8000">/* Réinitialise les tampons pour le déchiffrement */<br />    </span><span style="color: #0000BB">mcrypt_generic_init</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">, </span><span style="color: #0000BB">$key</span><span style="color: #007700">, </span><span style="color: #0000BB">$iv</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">$p_t </span><span style="color: #007700">= </span><span style="color: #0000BB">mdecrypt_generic</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">, </span><span style="color: #0000BB">$c_t</span><span style="color: #007700">);<br /><br />    </span><span style="color: #FF8000">/* Nettoie */<br />    </span><span style="color: #0000BB">mcrypt_generic_deinit</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">mcrypt_module_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">);<br />}<br /><br />if (</span><span style="color: #0000BB">strncmp</span><span style="color: #007700">(</span><span style="color: #0000BB">$p_t</span><span style="color: #007700">, </span><span style="color: #0000BB">$plain_text</span><span style="color: #007700">, </span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$plain_text</span><span style="color: #007700">)) == </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"ok\n"</span><span style="color: #007700">;<br />} else {<br />    echo </span><span style="color: #DD0000">"erreur\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
  <p class="simpara">
   L&#039;exemple ci-dessus montre comment vérifier que les données avant
   chiffrement sont bien les mêmes que celles après
   chiffrement/déchiffrement. Il est très important de réinitialiser
   le buffer de chiffrement avec <span class="function"><a href="function.mcrypt-generic-init.php" class="function">mcrypt_generic_init()</a></span>
   avant de déchiffrer les données.
  </p>
  <p class="simpara">
   Le gestionnaire de déchiffrement doit toujours être initialisé
   par la fonction <span class="function"><a href="function.mcrypt-generic-init.php" class="function">mcrypt_generic_init()</a></span> avec une clé
   et un VI avant d&#039;appeler cette fonction. Lorsque le chiffrement est fait,
   il faut qu&#039;on libère les données chiffrées en appelant
   <span class="function"><a href="function.mcrypt-generic-deinit.php" class="function">mcrypt_generic_deinit()</a></span>.
   Voir <span class="function"><a href="function.mcrypt-module-open.php" class="function">mcrypt_module_open()</a></span> pour un exemple.
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mdecrypt-generic-seealso">
  <h3 class="title">Voir aussi</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.mcrypt-generic.php" class="function" rel="rdfs-seeAlso">mcrypt_generic()</a> - Chiffre les donn&eacute;es</span></li>
   <li><span class="function"><a href="function.mcrypt-generic-init.php" class="function" rel="rdfs-seeAlso">mcrypt_generic_init()</a> - Initialise tous les tampons n&eacute;cessaires</span></li>
   <li><span class="function"><a href="function.mcrypt-generic-deinit.php" class="function" rel="rdfs-seeAlso">mcrypt_generic_deinit()</a> - Pr&eacute;pare le module pour le d&eacute;chargement</span></li>
  </ul>
 </div>

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