<?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-public-encrypt.php',
    1 => 'openssl_public_encrypt',
    2 => 'Encrypts data with public key',
  ),
  'up' => 
  array (
    0 => 'ref.openssl.php',
    1 => 'Функції OpenSSL',
  ),
  'prev' => 
  array (
    0 => 'function.openssl-public-decrypt.php',
    1 => 'openssl_public_decrypt',
  ),
  'next' => 
  array (
    0 => 'function.openssl-random-pseudo-bytes.php',
    1 => 'openssl_random_pseudo_bytes',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/openssl/functions/openssl-public-encrypt.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.openssl-public-encrypt" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">openssl_public_encrypt</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">openssl_public_encrypt</span> &mdash; <span class="dc-title">Encrypts data with public key</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.openssl-public-encrypt-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>openssl_public_encrypt</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">&$encrypted_data</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><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">$public_key</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">$padding</code><span class="initializer"> = <strong><code><a href="openssl.padding.php#constant.openssl-pkcs1-padding">OPENSSL_PKCS1_PADDING</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_public_encrypt()</strong></span> encrypts <code class="parameter">data</code>
   with public <code class="parameter">public_key</code> and stores the result into
   <code class="parameter">encrypted_data</code>. Encrypted data can be decrypted via
   <span class="function"><a href="function.openssl-private-decrypt.php" class="function">openssl_private_decrypt()</a></span>. 
  </p>
  <p class="para">
   This function can be used e.g. to encrypt message which can be then read
   only by owner of the private key. It can be also used to store secure data
   in database.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-public-encrypt-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">data</code></dt>
     <dd>
      <p class="para">
      </p>
     </dd>
    
    
     <dt><code class="parameter">encrypted_data</code></dt>
     <dd>
      <p class="para">
       This will hold the result of the encryption.
      </p>
     </dd>
    
    
     <dt><code class="parameter">public_key</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">public_key</code> must be the public key that corresponds
       to the private key that will be used to decrypt the data.
      </p>
     </dd>
    
    
     <dt><code class="parameter">padding</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">padding</code> can be one of
       <strong><code><a href="openssl.padding.php#constant.openssl-pkcs1-padding">OPENSSL_PKCS1_PADDING</a></code></strong>,
       <strong><code><a href="openssl.padding.php#constant.openssl-sslv23-padding">OPENSSL_SSLV23_PADDING</a></code></strong>,
       <strong><code><a href="openssl.padding.php#constant.openssl-pkcs1-oaep-padding">OPENSSL_PKCS1_OAEP_PADDING</a></code></strong>,
       <strong><code><a href="openssl.padding.php#constant.openssl-no-padding">OPENSSL_NO_PADDING</a></code></strong>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-public-encrypt-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-public-encrypt-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">public_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</code>
       was accepted.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 seealso" id="refsect1-function.openssl-public-encrypt-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.openssl-private-encrypt.php" class="function" rel="rdfs-seeAlso">openssl_private_encrypt()</a> - Encrypts data with private key</span></li>
    <li><span class="function"><a href="function.openssl-private-decrypt.php" class="function" rel="rdfs-seeAlso">openssl_private_decrypt()</a> - Decrypts data with private key</span></li>
   </ul>
  </p>
 </div>


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