<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.sodium.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.sodium-crypto-pwhash.php',
    1 => 'sodium_crypto_pwhash',
    2 => 'Derive a key from a password, using Argon2',
  ),
  'up' => 
  array (
    0 => 'ref.sodium.php',
    1 => 'Sodium Funktionen',
  ),
  'prev' => 
  array (
    0 => 'function.sodium-crypto-kx-server-session-keys.php',
    1 => 'sodium_crypto_kx_server_session_keys',
  ),
  'next' => 
  array (
    0 => 'function.sodium-crypto-pwhash-scryptsalsa208sha256.php',
    1 => 'sodium_crypto_pwhash_scryptsalsa208sha256',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/sodium/functions/sodium-crypto-pwhash.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.sodium-crypto-pwhash" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sodium_crypto_pwhash</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.2.0, PHP 8)</p><p class="refpurpose"><span class="refname">sodium_crypto_pwhash</span> &mdash; <span class="dc-title">Derive a key from a password, using Argon2</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.sodium-crypto-pwhash-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>sodium_crypto_pwhash</strong></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">$length</code></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">$password</code></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">$salt</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">$opslimit</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">$memlimit</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">$algo</code><span class="initializer"> = <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-alg-default">SODIUM_CRYPTO_PWHASH_ALG_DEFAULT</a></code></strong></span></span><br>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="simpara">
   This function provides low-level access to libsodium&#039;s crypto_pwhash key derivation function. Unless you have specific reason to use this function, you should use <span class="function"><a href="function.sodium-crypto-pwhash-str.php" class="function">sodium_crypto_pwhash_str()</a></span> or <span class="function"><a href="function.password-hash.php" class="function">password_hash()</a></span> functions instead.
  </p>
  <p class="simpara">
   A common reason to use this particular function is to derive the seeds for cryptographic keys from a password and salt,
   and then use these seeds to generate the actual keys needed for some purpose (e.g. <span class="function"><a href="function.sodium-crypto-sign-detached.php" class="function">sodium_crypto_sign_detached()</a></span>).
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.sodium-crypto-pwhash-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <dl>
   
    <dt><code class="parameter">length</code></dt>
    <dd>
     <span class="simpara">
      <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>; The length of the password hash to generate, in bytes.
     </span>
    </dd>
   
   
    <dt><code class="parameter">password</code></dt>
    <dd>
     <span class="simpara">
      <span class="type"><a href="language.types.string.php" class="type string">string</a></span>; The password to generate a hash for.
     </span>
    </dd>
   
   
    <dt><code class="parameter">salt</code></dt>
    <dd>
     <span class="simpara">
      A salt to add to the password before hashing. The salt should be unpredictable, ideally generated from a good random number source such as <span class="function"><a href="function.random-bytes.php" class="function">random_bytes()</a></span>, and have a length of exactly <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-saltbytes">SODIUM_CRYPTO_PWHASH_SALTBYTES</a></code></strong> bytes.
     </span>
    </dd>
   
   
    <dt><code class="parameter">opslimit</code></dt>
    <dd>
     <span class="simpara">
      Represents a maximum amount of computations to perform. Raising this number will make the function require more CPU cycles to compute a key. There are some constants available to set the operations limit to appropriate values depending on intended use, in order of strength: <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-opslimit-interactive">SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE</a></code></strong>, <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-opslimit-moderate">SODIUM_CRYPTO_PWHASH_OPSLIMIT_MODERATE</a></code></strong> and <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-opslimit-sensitive">SODIUM_CRYPTO_PWHASH_OPSLIMIT_SENSITIVE</a></code></strong>.
     </span>
    </dd>
   
   
    <dt><code class="parameter">memlimit</code></dt>
    <dd>
     <span class="simpara">
      The maximum amount of RAM that the function will use, in bytes. There are constants to help you choose an appropriate value, in order of size: <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-memlimit-interactive">SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE</a></code></strong>, <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-memlimit-moderate">SODIUM_CRYPTO_PWHASH_MEMLIMIT_MODERATE</a></code></strong>, and <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-memlimit-sensitive">SODIUM_CRYPTO_PWHASH_MEMLIMIT_SENSITIVE</a></code></strong>. Typically these should be paired with the matching <code class="parameter">opslimit</code> values.
     </span>
    </dd>
   
   
    <dt><code class="parameter">algo</code></dt>
    <dd>
     <span class="simpara">
      <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> A number indicating the hash algorithm to use. By default <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-alg-default">SODIUM_CRYPTO_PWHASH_ALG_DEFAULT</a></code></strong> (the currently recommended algorithm, which can change from one version of libsodium to another), or explicitly using <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-alg-argon2id13">SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13</a></code></strong>, representing the Argon2id algorithm version 1.3.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sodium-crypto-pwhash-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="simpara">
   Returns the derived key. The return value is a binary string of the hash, not an ASCII-encoded representation, and does not contain additional information about the parameters used to create the hash, so you will need to keep that information if you are ever going to verify the password in future. Use <span class="function"><a href="function.sodium-crypto-pwhash-str.php" class="function">sodium_crypto_pwhash_str()</a></span> to avoid needing to do all that.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.sodium-crypto-pwhash-examples">
  <h3 class="title">Beispiele</h3>
  <div class="example" id="example-1">
   <p><strong>Beispiel #1 <span class="function"><strong>sodium_crypto_pwhash()</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: #FF8000">//Need to keep the salt if we're ever going to be able to check this password<br /></span><span style="color: #0000BB">$salt </span><span style="color: #007700">= </span><span style="color: #0000BB">random_bytes</span><span style="color: #007700">(</span><span style="color: #0000BB">SODIUM_CRYPTO_PWHASH_SALTBYTES</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//Using bin2hex to keep output readable<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">bin2hex</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">sodium_crypto_pwhash</span><span style="color: #007700">(<br />        </span><span style="color: #0000BB">16</span><span style="color: #007700">, </span><span style="color: #FF8000">// == 128 bits<br />        </span><span style="color: #DD0000">'password'</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">$salt</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13<br />    </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">a18f346ba57992eb7e4ae6abf3fd30ee</pre>
</div>
   </div>
  </div>
 </div>


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