<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.openssl.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.openssl-random-pseudo-bytes.php',
    1 => 'openssl_random_pseudo_bytes',
    2 => 'G&eacute;n&egrave;re une cha&icirc;ne pseudo-al&eacute;atoire d\'octets',
  ),
  'up' => 
  array (
    0 => 'ref.openssl.php',
    1 => 'Fonctions OpenSSL',
  ),
  'prev' => 
  array (
    0 => 'function.openssl-public-encrypt.php',
    1 => 'openssl_public_encrypt',
  ),
  'next' => 
  array (
    0 => 'function.openssl-seal.php',
    1 => 'openssl_seal',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/openssl/functions/openssl-random-pseudo-bytes.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.openssl-random-pseudo-bytes" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">openssl_random_pseudo_bytes</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">openssl_random_pseudo_bytes</span> &mdash; <span class="dc-title">Génère une chaîne pseudo-aléatoire d&#039;octets</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.openssl-random-pseudo-bytes-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>openssl_random_pseudo_bytes</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$length</code></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter reference">&$strong_result</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   Génère une <a href="language.types.string.php" class="link">chaîne de caractères</a> pseudo-aléatoire d&#039;octets, dont la longueur est
   spécifiée par le paramètre <code class="parameter">length</code>.
  </p>
  <p class="para">
   Indique également si l&#039;algorithme fort de cryptologie a été utilisé pour
   produire ces octets pseudo-aléatoires, en utilisant le paramètre
   <code class="parameter">strong_result</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-random-pseudo-bytes-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">length</code></dt>
     <dd>
      <p class="para">
       La taille désirée pour la chaîne d&#039;octets. Doit être un nombre entier positif
       inférieur ou égal à <code class="literal">2147483647</code>. PHP va tenter de
       transtyper ce paramètre en un entier non nul pour l&#039;utiliser. 
      </p>
     </dd>
    
    
     <dt><code class="parameter">strong_result</code></dt>
     <dd>
      <p class="para">
       Si fourni, détermine si l&#039;algorithme de cryptologie utilisé
       était cryptographiquement fort, c.-à-d. sécurisé pour être utilisé avec GPG, les mots
       de passe, etc. <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> s&#039;il l&#039;est, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> sinon.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-random-pseudo-bytes-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne la chaîne d&#039;octets générée.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.openssl-random-pseudo-bytes-errors">
  <h3 class="title">Erreurs / Exceptions</h3>
  <p class="para">
   <span class="function"><strong>openssl_random_pseudo_bytes()</strong></span> lance une <span class="classname"><a href="class.exception.php" class="classname">Exception</a></span> en cas d&#039;échec.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.openssl-random-pseudo-bytes-changelog">
  <h3 class="title">Historique</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">strong_result</code> est désormais nullable.
      </td>
     </tr>

     <tr>
      <td>7.4.0</td>
      <td>
       La fonction ne retourne plus <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> en cas d&#039;échec, mais lance une <span class="classname"><a href="class.exception.php" class="classname">Exception</a></span> à la place.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>

 
 <div class="refsect1 examples" id="refsect1-function.openssl-random-pseudo-bytes-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple <span class="function"><strong>openssl_random_pseudo_bytes()</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: #007700">for (</span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">1</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">&lt;= </span><span style="color: #0000BB">4</span><span style="color: #007700">; </span><span style="color: #0000BB">$i</span><span style="color: #007700">++) {<br />    </span><span style="color: #0000BB">$bytes </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_random_pseudo_bytes</span><span style="color: #007700">(</span><span style="color: #0000BB">$i</span><span style="color: #007700">, </span><span style="color: #0000BB">$cstrong</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">$hex   </span><span style="color: #007700">= </span><span style="color: #0000BB">bin2hex</span><span style="color: #007700">(</span><span style="color: #0000BB">$bytes</span><span style="color: #007700">);<br /><br />    echo </span><span style="color: #DD0000">"Longueur : Octets : </span><span style="color: #0000BB">$i</span><span style="color: #DD0000"> et Hex: " </span><span style="color: #007700">. </span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$hex</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">$hex</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$cstrong</span><span style="color: #007700">);<br />    echo </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Résultat de l&#039;exemple ci-dessus est similaire à :</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Longueur : Octets : 1 et  Hex: 2
string(2) &quot;42&quot;
bool(true)

Longueur : Octets : 2 et Hex: 4
string(4) &quot;dc6e&quot;
bool(true)

Longueur : Octets : 3 et Hex: 6
string(6) &quot;288591&quot;
bool(true)

Longueur : Octets : 4 et Hex: 8
string(8) &quot;ab86d144&quot;
bool(true)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.openssl-random-pseudo-bytes-seealso">
  <h3 class="title">Voir aussi</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.random-bytes.php" class="function" rel="rdfs-seeAlso">random_bytes()</a> - R&eacute;cup&egrave;re des octets al&eacute;atoires cryptographiquement s&eacute;curis&eacute;s</span></li>
   <li><span class="function"><a href="function.bin2hex.php" class="function" rel="rdfs-seeAlso">bin2hex()</a> - Convertit des donn&eacute;es binaires en repr&eacute;sentation hexad&eacute;cimale</span></li>
   <li><span class="function"><a href="function.crypt.php" class="function" rel="rdfs-seeAlso">crypt()</a> - Hachage &agrave; sens unique (ind&eacute;chiffrable)</span></li>
   <li><span class="function"><a href="function.random-int.php" class="function" rel="rdfs-seeAlso">random_int()</a> - R&eacute;cup&egrave;re un entier s&eacute;lectionn&eacute; de mani&egrave;re uniforme et cryptographiquement s&eacute;curis&eacute;e</span></li>
  </ul>
 </div>

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