<?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-box.php',
    1 => 'sodium_crypto_box',
    2 => '認証付きの公開鍵による暗号化',
  ),
  'up' => 
  array (
    0 => 'ref.sodium.php',
    1 => 'Sodium 関数',
  ),
  'prev' => 
  array (
    0 => 'function.sodium-crypto-auth-verify.php',
    1 => 'sodium_crypto_auth_verify',
  ),
  'next' => 
  array (
    0 => 'function.sodium-crypto-box-keypair.php',
    1 => 'sodium_crypto_box_keypair',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/sodium/functions/sodium-crypto-box.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.sodium-crypto-box" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sodium_crypto_box</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.2.0, PHP 8)</p><p class="refpurpose"><span class="refname">sodium_crypto_box</span> &mdash; <span class="dc-title">認証付きの公開鍵による暗号化</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.sodium-crypto-box-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>sodium_crypto_box</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">$message</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$nonce</code></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">$key_pair</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="simpara">
   非対称(公開鍵)暗号を使ってメッセージを暗号化します。
  </p>
  <p class="simpara">
   <span class="function"><strong>sodium_crypto_box()</strong></span>
   というプレフィックスが付いた関数が使うアルゴリズムは、
   Elliptic Curve Diffie-Hellman over the Montgomery curve, Curve25519;
   略して X25519 です。
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.sodium-crypto-box-parameters">
  <h3 class="title">パラメータ</h3>
  <dl>
   
    <dt><code class="parameter">message</code></dt>
    <dd>
     <span class="simpara">
      暗号化するメッセージ
     </span>
    </dd>
   
   
    <dt><code class="parameter">nonce</code></dt>
    <dd>
     <span class="simpara">
      メッセージごとに一度だけ使われる数値。
      長さは24バイトです。
      これは、
      (たとえば、<span class="function"><a href="function.random-bytes.php" class="function">random_bytes()</a></span>を使って)
      ランダムな値を生成するのに十分大きな長さです。
     </span>
    </dd>
   
   
    <dt><code class="parameter">key_pair</code></dt>
    <dd>
     <span class="simpara">
      <span class="function"><a href="function.sodium-crypto-box-keypair-from-secretkey-and-publickey.php" class="function">sodium_crypto_box_keypair_from_secretkey_and_publickey()</a></span>
      を参照ください。
      この鍵ペアには、
      送信者の X25519 形式の秘密鍵と、
      受信者の X25519 形式の公開鍵が含まれているべきです。
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sodium-crypto-box-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="simpara">
   暗号化されたメッセージ(暗号化済みのテキストと、認証タグ)を返します。
   暗号化済みのテキストは、
   生のバイナリ文字列の分だけ、
   プレーンテキストより16バイト長くなっています。
   安全なエンコード方法については、
   <span class="function"><a href="function.sodium-bin2base64.php" class="function">sodium_bin2base64()</a></span> を参照ください。
  </p>
 </div>



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