<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.mhash.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.mhash-keygen-s2k.php',
    1 => 'mhash_keygen_s2k',
    2 => 'Generates a key',
  ),
  'up' => 
  array (
    0 => 'ref.mhash.php',
    1 => 'Mhash Functions',
  ),
  'prev' => 
  array (
    0 => 'function.mhash-get-hash-name.php',
    1 => 'mhash_get_hash_name',
  ),
  'next' => 
  array (
    0 => 'book.openssl.php',
    1 => 'OpenSSL',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/mhash/functions/mhash-keygen-s2k.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.mhash-keygen-s2k" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mhash_keygen_s2k</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mhash_keygen_s2k</span> &mdash; <span class="dc-title">Generates a key</span></p>

 </div>

 <div id="function.mhash-keygen-s2k-refsynopsisdiv">
  <div class="warning"><strong class="warning">Warning</strong><p class="simpara">This function has been
<em>DEPRECATED</em> as of PHP 8.1.0. Relying on this function
is highly discouraged.</p></div>
 </div>
 
 <div class="refsect1 description" id="refsect1-function.mhash-keygen-s2k-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="attribute"><a href="class.deprecated.php">#[\Deprecated]</a> </span><br>
   <span class="methodname"><strong>mhash_keygen_s2k</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">$algo</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">$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">$length</code></span><br>): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Generates a key according to the given <code class="parameter">algo</code>, using an user
   provided <code class="parameter">password</code>.
  </p>
  <p class="para">
   This is the Salted S2K algorithm as specified in the OpenPGP
   document (<a href="https://datatracker.ietf.org/doc/html/rfc2440" class="link external">&raquo;&nbsp;RFC 2440</a>).
  </p>
  <p class="para">
   Keep in mind that user supplied passwords are not really suitable
   to be used as keys in cryptographic algorithms, since users normally
   choose keys they can write on keyboard. These passwords use
   only 6 to 7 bits per character (or less). It is highly recommended
   to use some kind of transformation (like this function) to the user
   supplied key.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mhash-keygen-s2k-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">algo</code></dt>
     <dd>
      <p class="para">
       The hash ID used to create the key.
       One of the <strong><code>MHASH_hashname</code></strong> constants.
      </p>
     </dd>
    
    
     <dt><code class="parameter">password</code></dt>
     <dd>
      <p class="para">
       An user supplied password.
      </p>
     </dd>
    
    
     <dt><code class="parameter">salt</code></dt>
     <dd>
      <p class="para">
       Must be different and random enough for every key you generate in
       order to create different keys. Because <code class="parameter">salt</code>
       must be known when you check the keys, it is a good idea to append
       the key to it. Salt has a fixed length of 8 bytes and will be padded
       with zeros if you supply less bytes.
      </p>
     </dd>
    
    
     <dt><code class="parameter">length</code></dt>
     <dd>
      <p class="para">
       The key length, in bytes.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mhash-keygen-s2k-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the generated key as a string, or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on error.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.mhash-keygen-s2k-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.1.0</td>
       <td>
        This function has been deprecated.
        Use the <a href="ref.hash.php" class="link"><code class="literal">hash_*()</code> functions</a> instead.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

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