<?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 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.openssl-open.php',
    1 => 'openssl_open',
    2 => 'Open sealed data',
  ),
  'up' => 
  array (
    0 => 'ref.openssl.php',
    1 => 'Функції OpenSSL',
  ),
  'prev' => 
  array (
    0 => 'function.openssl-get-publickey.php',
    1 => 'openssl_get_publickey',
  ),
  'next' => 
  array (
    0 => 'function.openssl-pbkdf2.php',
    1 => 'openssl_pbkdf2',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/openssl/functions/openssl-open.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

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

 </div>
 
 <div class="refsect1 description" id="refsect1-function.openssl-open-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>openssl_open</strong></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">$data</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 reference">&$output</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">$encrypted_key</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="attribute"><a href="class.sensitiveparameter.php">#[\SensitiveParameter]</a> </span><span class="type"><span class="type"><a href="class.opensslasymmetrickey.php" class="type OpenSSLAsymmetricKey">OpenSSLAsymmetricKey</a></span>|<span class="type"><a href="class.opensslcertificate.php" class="type OpenSSLCertificate">OpenSSLCertificate</a></span>|<span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$private_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"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$iv</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>openssl_open()</strong></span> opens (decrypts) <code class="parameter">data</code> using an envelope
   key that is decrypted from <code class="parameter">encrypted_key</code> using
   <code class="parameter">private_key</code>. The decryption is done using
   <code class="parameter">cipher_algo</code> and <code class="parameter">iv</code>. The IV is required only if the
   cipher method requires it. The function fills <code class="parameter">output</code> with the decrypted
   data. The envelope key is usually generated when the data are sealed using a public key that is
   associated with the private key. See <span class="function"><a href="function.openssl-seal.php" class="function">openssl_seal()</a></span> for more information.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-open-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">data</code></dt>
     <dd>
      <p class="para">
       The sealed data.
      </p>
     </dd>
    
    
     <dt><code class="parameter">output</code></dt>
     <dd>
      <p class="para">
       If the call is successful the opened data is returned in this parameter.
      </p>
     </dd>
    
    
     <dt><code class="parameter">encrypted_key</code></dt>
     <dd>
      <p class="para">
       The encrypted symmetric key that can be decrypted using <code class="parameter">private_key</code>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">private_key</code></dt>
     <dd>
      <p class="para">
       The private key used for decrypting <code class="parameter">encrypted_key</code>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">cipher_algo</code></dt>
     <dd>
      <p class="para">
       The cipher method used for decryption of <code class="parameter">data</code>.
       <div class="caution"><strong class="caution">Застереження</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 used 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>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-open-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Повертає <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> у разі успіху або <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> в разі помилки.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.openssl-open-changelog">
  <h3 class="title">Журнал змін</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Версія</th>
      <th>Опис</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">private_key</code> accepts an <span class="classname"><a href="class.opensslasymmetrickey.php" class="classname">OpenSSLAsymmetricKey</a></span>
       or <span class="classname"><a href="class.opensslcertificate.php" class="classname">OpenSSLCertificate</a></span> instance now;
       previously, a <a href="language.types.resource.php" class="link">resource</a> of type <code class="literal">OpenSSL key</code> or <code class="literal">OpenSSL X.509 CSR</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>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.openssl-open-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <span class="function"><strong>openssl_open()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// $sealed, $env_key and $iv are assumed to contain the sealed data, our<br />// envelope key and IV. All given to us by the sealer.<br /><br />// Fetch private key from file located in private_key.pem<br /></span><span style="color: #0000BB">$pkey </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_get_privatekey</span><span style="color: #007700">(</span><span style="color: #DD0000">"file://private_key.pem"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Decrypt the data and store it in $open<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">openssl_open</span><span style="color: #007700">(</span><span style="color: #0000BB">$sealed</span><span style="color: #007700">, </span><span style="color: #0000BB">$open</span><span style="color: #007700">, </span><span style="color: #0000BB">$env_key</span><span style="color: #007700">, </span><span style="color: #0000BB">$pkey</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">)) {<br />    echo </span><span style="color: #DD0000">"Here is the opened data: "</span><span style="color: #007700">, </span><span style="color: #0000BB">$open</span><span style="color: #007700">;<br />} else {<br />    echo </span><span style="color: #DD0000">"Failed to open data"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 seealso" id="refsect1-function.openssl-open-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.openssl-seal.php" class="function" rel="rdfs-seeAlso">openssl_seal()</a> - Seal (encrypt) data</span></li>
   </ul>
  </p>
 </div>


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