<?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 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.openssl-seal.php',
    1 => 'openssl_seal',
    2 => 'Seal (encrypt) data',
  ),
  'up' => 
  array (
    0 => 'ref.openssl.php',
    1 => 'OpenSSL Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.openssl-random-pseudo-bytes.php',
    1 => 'openssl_random_pseudo_bytes',
  ),
  'next' => 
  array (
    0 => 'function.openssl-sign.php',
    1 => 'openssl_sign',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/openssl/functions/openssl-seal.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.openssl-seal" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">openssl_seal</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">openssl_seal</span> &mdash; <span class="dc-title">Seal (encrypt) data</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.openssl-seal-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>openssl_seal</strong></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">$data</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 reference">&$sealed_data</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter reference">&$encrypted_keys</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$public_key</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">$cipher_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 reference">&$iv</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>openssl_seal()</strong></span> seals (encrypts) <code class="parameter">data</code> using the
   specified <code class="parameter">cipher_algo</code> with a randomly generated secret key. The key is
   then encrypted with each of the public keys in <code class="parameter">public_key</code> array,
   and each encrypted envelope key is returned in <code class="parameter">encrypted_keys</code>. This allows
   sealed data to be sent to multiple recipients (provided their public keys are available). Each
   recipient must receive both the sealed data and the envelope key that was encrypted with the
   recipient&#039;s public key. The IV (Initialization Vector) is generated, and its value is returned in
   <code class="parameter">iv</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-seal-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">data</code></dt>
     <dd>
      <p class="para">
       The data to seal.
      </p>
     </dd>
    
    
     <dt><code class="parameter">sealed_data</code></dt>
     <dd>
      <p class="para">
       The sealed data.
      </p>
     </dd>
    
    
     <dt><code class="parameter">encrypted_keys</code></dt>
     <dd>
      <p class="para">
       Array of encrypted keys.
      </p>
     </dd>
    
    
     <dt><code class="parameter">public_key</code></dt>
     <dd>
      <p class="para">
       Array of <span class="classname"><a href="class.opensslasymmetrickey.php" class="classname">OpenSSLAsymmetricKey</a></span> instances containing public keys.
      </p>
     </dd>
    
    
     <dt><code class="parameter">cipher_algo</code></dt>
     <dd>
      <p class="para">
       The cipher method.
       <div class="caution"><strong class="caution">Attenzione</strong>
        <p class="simpara">
         The default value for PHP versions prior to 8.0 is (<code class="literal">&#039;RC4&#039;</code>) which is
         considered insecure. It is strongly recommended to explicitly specify a secure cipher
         method.
        </p>
       </div>
      </p>
     </dd>
    
    
     <dt><code class="parameter">iv</code></dt>
     <dd>
      <p class="para">
       The initialization vector for decryption of <code class="parameter">data</code>. It is required if
       the cipher method requires IV. This can be found out by calling
       <span class="function"><a href="function.openssl-cipher-iv-length.php" class="function">openssl_cipher_iv_length()</a></span> with <code class="parameter">cipher_algo</code>.
      </p>
      <div class="caution"><strong class="caution">Attenzione</strong>
       <p class="simpara">
        The IV cannot be set explicitly. Any value set in it is overwritten by randomly generated
        value.
       </p>
      </div>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-seal-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Returns the length of the sealed data on success, or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on error.
   If successful the sealed data is returned in
   <code class="parameter">sealed_data</code>, and the envelope keys in
   <code class="parameter">encrypted_keys</code>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.openssl-seal-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versione</th>
      <th>Descrizione</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">public_key</code> accepts an <span class="type"><a href="language.types.array.php" class="type array">array</a></span> of
       <span class="classname"><a href="class.opensslasymmetrickey.php" class="classname">OpenSSLAsymmetricKey</a></span> instances now;
       previously, an <span class="type"><a href="language.types.array.php" class="type array">array</a></span> of <a href="language.types.resource.php" class="link">resource</a>s of type <code class="literal">OpenSSL key</code>
       was accepted.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">cipher_algo</code> is no longer an optional parameter.
      </td>
     </tr>

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

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.openssl-seal-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>openssl_seal()</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">// $data is assumed to contain the data to be sealed<br /></span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #DD0000">"test"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// fetch public keys<br /></span><span style="color: #0000BB">$pk1 </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_get_publickey</span><span style="color: #007700">(</span><span style="color: #DD0000">"file://cert1.pem"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$pk2 </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_get_publickey</span><span style="color: #007700">(</span><span style="color: #DD0000">"file://cert2.pem"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// seal message, only owners of $pk1 and $pk2 can decrypt $sealed with keys<br />// $ekeys[0] and $ekeys[1] respectively.<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">openssl_seal</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">, </span><span style="color: #0000BB">$sealed</span><span style="color: #007700">, </span><span style="color: #0000BB">$ekeys</span><span style="color: #007700">, array(</span><span style="color: #0000BB">$pk1</span><span style="color: #007700">, </span><span style="color: #0000BB">$pk2</span><span style="color: #007700">), </span><span style="color: #DD0000">'AES256'</span><span style="color: #007700">, </span><span style="color: #0000BB">$iv</span><span style="color: #007700">) &gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br />    </span><span style="color: #FF8000">// possibly store the $sealed and $iv values and use later in openssl_open<br />    </span><span style="color: #007700">echo </span><span style="color: #DD0000">"success\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.openssl-seal-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.openssl-open.php" class="function" rel="rdfs-seeAlso">openssl_open()</a> - Open sealed data</span></li>
   </ul>
  </p>
 </div>


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