<?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 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.sodium-crypto-pwhash-str.php',
    1 => 'sodium_crypto_pwhash_str',
    2 => 'ASCII 文字でエンコードされたハッシュ値を得る',
  ),
  'up' => 
  array (
    0 => 'ref.sodium.php',
    1 => 'Sodium 関数',
  ),
  'prev' => 
  array (
    0 => 'function.sodium-crypto-pwhash-scryptsalsa208sha256-str-verify.php',
    1 => 'sodium_crypto_pwhash_scryptsalsa208sha256_str_verify',
  ),
  'next' => 
  array (
    0 => 'function.sodium-crypto-pwhash-str-needs-rehash.php',
    1 => 'sodium_crypto_pwhash_str_needs_rehash',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/sodium/functions/sodium-crypto-pwhash-str.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-str" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sodium_crypto_pwhash_str</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.2.0, PHP 8)</p><p class="refpurpose"><span class="refname">sodium_crypto_pwhash_str</span> &mdash; <span class="dc-title">ASCII 文字でエンコードされたハッシュ値を得る</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.sodium-crypto-pwhash-str-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>sodium_crypto_pwhash_str</strong></span>(<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>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$opslimit</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$memlimit</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="simpara">
   ランダムに生成されたソルト値と、
   CPU とメモリへの攻撃に強いハッシュアルゴリズムを使い、
   指定されたメモリとCPUの使用量の最大値に基づき、
   パスワードの保存に適した ASCII 文字でエンコードされたハッシュを生成します。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.sodium-crypto-pwhash-str-parameters">
  <h3 class="title">パラメータ</h3>
  <dl>
   
    <dt><code class="parameter">password</code></dt>
    <dd>
     <span class="simpara">
      ハッシュを生成するパスワードを文字列で指定します。
     </span>
    </dd>
   
   
    <dt><code class="parameter">opslimit</code></dt>
    <dd>
     <span class="simpara">
      実際に行う計算処理の最大量。
      この値を大きくすると、
      キーを計算するのに必要なCPUサイクルが増加します。
      意図した使い方次第で、
      適切な値の上限値を設定するために、いくつかの定数が存在します。
      弱いものから強いものへと並べると、以下のとおりです:
      <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>,
      <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">
      この関数が使用するメモリの最大値をバイト単位で指定します。
      適切な値を選ぶために、ヘルパとなる定数が存在します。
      サイズの順に、以下の通りです:
      <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>,
      <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-memlimit-sensitive">SODIUM_CRYPTO_PWHASH_MEMLIMIT_SENSITIVE</a></code></strong>
      があります。
      これらの値は、<code class="parameter">opslimit</code>
      と一致するものとペアになるべきです。
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sodium-crypto-pwhash-str-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="simpara">
   ハッシュ化されたパスワードを返します。
  </p>
  <p class="simpara">
   同じパスワードから同じパスワードハッシュを生成するには、
   <code class="parameter">opslimit</code> と
   <code class="parameter">memlimit</code> の値を同じにしなければいけません。
   これらは生成されたハッシュに埋め込まれているので、
   ハッシュを検証する際に必要な全てが含まれています。
   これによって、
   <span class="function"><a href="function.sodium-crypto-pwhash-str-verify.php" class="function">sodium_crypto_pwhash_str_verify()</a></span>
   関数が、他の引数に関する情報を追加で保存せずにハッシュを検証できるのです。
  </p>
 </div>


  <div class="refsect1 examples" id="refsect1-function.sodium-crypto-pwhash-str-examples">
  <h3 class="title">例</h3>
  <div class="example" id="example-1">
   <p><strong>例1 <span class="function"><strong>sodium_crypto_pwhash_str()</strong></span> の例</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$password </span><span style="color: #007700">= </span><span style="color: #DD0000">'password'</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">sodium_crypto_pwhash_str</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">$password</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<br /></span><span style="color: #007700">);</span></span></code></div>
   </div>

   <div class="example-contents"><p>上の例の出力は、
たとえば以下のようになります。</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">$argon2id$v=19$m=65536,t=2,p=1$oWIfdaXwWwhVmovOBc2NAQ$EbsZ+JnZyyavkafS0hoc4HdaOB0ILWZESAZ7kVGa+Iw</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 notes" id="refsect1-function.sodium-crypto-pwhash-str-notes">
  <h3 class="title">注意</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    ハッシュ値は
    Argon2ID アルゴリズムを使って計算されます。
    このアルゴリズムは、GPU に対する攻撃と
    サイドチャネル攻撃の両方に対する耐性を提供します。
    <span class="function"><a href="function.password-hash.php" class="function">password_hash()</a></span> と異なり、
    salt の引数は存在せず(自動生成されます)、
    <code class="parameter">opslimit</code> と
    <code class="parameter">memlimit</code> の値が必須になっています。
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.sodium-crypto-pwhash-str-seealso">
  <h3 class="title">参考</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.sodium-crypto-pwhash-str-verify.php" class="function" rel="rdfs-seeAlso">sodium_crypto_pwhash_str_verify()</a> - パスワードが、ハッシュ値と一致するかを調べる</span></li>
   <li><span class="function"><a href="function.sodium-crypto-pwhash.php" class="function" rel="rdfs-seeAlso">sodium_crypto_pwhash()</a> - Argon2 アルゴリズムを使い、パスワードからキーを導出する</span></li>
   <li><span class="function"><a href="function.password-hash.php" class="function" rel="rdfs-seeAlso">password_hash()</a> - パスワードハッシュを作る</span></li>
   <li><span class="function"><a href="function.password-verify.php" class="function" rel="rdfs-seeAlso">password_verify()</a> - パスワードがハッシュにマッチするかどうかを調べる</span></li>
   <li><a href="https://download.libsodium.org/doc/password_hashing/the_argon2i_function.html" class="link external">&raquo;&nbsp;Libsodium Argon2 docs</a></li>
  </ul>
 </div>



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