<?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 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.openssl-random-pseudo-bytes.php',
    1 => 'openssl_random_pseudo_bytes',
    2 => 'Generate a pseudo-random string of bytes',
  ),
  'up' => 
  array (
    0 => 'ref.openssl.php',
    1 => 'OpenSSL-Funktionen',
  ),
  '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' => 'en',
    '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">Generate a pseudo-random string of bytes</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.openssl-random-pseudo-bytes-description">
  <h3 class="title">Beschreibung</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">
   Generates a <span class="type"><a href="language.types.string.php" class="type string">string</a></span> of pseudo-random bytes, with the number of bytes
   determined by the <code class="parameter">length</code> parameter. 
  </p>
  <p class="para">
   It also indicates if a cryptographically strong algorithm was used to produce the
   pseudo-random bytes, and does this via the optional <code class="parameter">strong_result</code>
   parameter. It&#039;s rare for this to be <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, but some systems may be broken or old.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-random-pseudo-bytes-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">length</code></dt>
     <dd>
      <p class="para">
       The length of the desired string of bytes. Must be a positive integer less than or equal to <code class="literal">2147483647</code>. PHP will
       try to cast this parameter to a non-null integer to use it. 
      </p>
     </dd>
    
    
     <dt><code class="parameter">strong_result</code></dt>
     <dd>
      <p class="para">
       If passed into the function, this will hold a <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> value that determines
       if the algorithm used was &quot;cryptographically strong&quot;, e.g., safe for usage with GPG, 
       passwords, etc. <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> if it did, otherwise <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-random-pseudo-bytes-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   Returns the generated <a href="language.types.string.php" class="link">String</a> of bytes.
  </p>
 </div>

 
 <div class="refsect1 errors" id="refsect1-function.openssl-random-pseudo-bytes-errors">
  <h3 class="title">Fehler/Exceptions</h3>
  <p class="para">
   <span class="function"><strong>openssl_random_pseudo_bytes()</strong></span> throws an <span class="classname"><a href="class.exception.php" class="classname">Exception</a></span>
   on failure.
  </p>
 </div>


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

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">strong_result</code> is nullable now.
      </td>
     </tr>

     <tr>
      <td>7.4.0</td>
      <td>
       The function no longer returns <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure, but throws an <span class="classname"><a href="class.exception.php" class="classname">Exception</a></span> instead.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>

 <div class="refsect1 examples" id="refsect1-function.openssl-random-pseudo-bytes-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 <span class="function"><strong>openssl_random_pseudo_bytes()</strong></span> example</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">"Lengths: Bytes: </span><span style="color: #0000BB">$i</span><span style="color: #DD0000"> and 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>Das oben gezeigte Beispiel erzeugt
eine ähnliche Ausgabe wie:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Lengths: Bytes: 1 and Hex: 2
string(2) &quot;42&quot;
bool(true)

Lengths: Bytes: 2 and Hex: 4
string(4) &quot;dc6e&quot;
bool(true)

Lengths: Bytes: 3 and Hex: 6
string(6) &quot;288591&quot;
bool(true)

Lengths: Bytes: 4 and 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">Siehe auch</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.random-bytes.php" class="function" rel="rdfs-seeAlso">random_bytes()</a> - Get cryptographically secure random bytes</span></li>
   <li><span class="function"><a href="function.bin2hex.php" class="function" rel="rdfs-seeAlso">bin2hex()</a> - Wandelt Bin&auml;r-Daten in ihre hexadezimale Entsprechung um</span></li>
   <li><span class="function"><a href="function.crypt.php" class="function" rel="rdfs-seeAlso">crypt()</a> - Einweg-String-Hashing</span></li>
   <li><span class="function"><a href="function.random-int.php" class="function" rel="rdfs-seeAlso">random_int()</a> - Get a cryptographically secure, uniformly selected integer</span></li>
  </ul>
 </div>

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