<?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 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.openssl-pkey-derive.php',
    1 => 'openssl_pkey_derive',
    2 => 'Computes shared secret for public value of remote and local DH or ECDH key',
  ),
  'up' => 
  array (
    0 => 'ref.openssl.php',
    1 => 'OpenSSL-Funktionen',
  ),
  'prev' => 
  array (
    0 => 'function.openssl-pkcs7-verify.php',
    1 => 'openssl_pkcs7_verify',
  ),
  'next' => 
  array (
    0 => 'function.openssl-pkey-export.php',
    1 => 'openssl_pkey_export',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/openssl/functions/openssl-pkey-derive.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.openssl-pkey-derive" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">openssl_pkey_derive</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.3.0, PHP 8)</p><p class="refpurpose"><span class="refname">openssl_pkey_derive</span> &mdash; <span class="dc-title">Computes shared secret for public value of remote and local DH or ECDH key</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.openssl-pkey-derive-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">function</span> <span class="methodname"><strong>openssl_pkey_derive</strong></span>(<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>, <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>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$key_length</code><span class="initializer"> = 0</span></span>): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</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_pkey_derive()</strong></span> takes a set of a <code class="parameter">public_key</code>
   and <code class="parameter">private_key</code> and derives a shared secret, for either DH or EC keys.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-pkey-derive-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <dl>
   
    <dt><code class="parameter">public_key</code></dt>
    <dd>
     <p class="para">
      <code class="parameter">public_key</code> is the public key for the derivation.
      See <a href="openssl.certparams.php" class="link">Public/Private Key parameters</a> for a list of valid values.
     </p>
    </dd>
   
   
    <dt><code class="parameter">private_key</code></dt>
    <dd>
     <p class="para">
      <code class="parameter">private_key</code> is the private key for the derivation.
      See <a href="openssl.certparams.php" class="link">Public/Private Key parameters</a> for a list of valid values.
     </p>
    </dd>
   
   
    <dt><code class="parameter">key_length</code></dt>
    <dd>
     <p class="para">
      If not zero, will attempt to set the desired length of the derived secret.
     </p>
     <div class="caution"><strong class="caution">Achtung</strong>
      <p class="simpara">
       This parameter is deprecated and should not be used, as it does not work as expected. It
       never returns a secret longer than the size of the prime. If the desired length is smaller
       than the size of the prime, it truncates the length only for ECDH keys but fails for DH keys.
      </p>
     </div>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-pkey-derive-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   The derived secret on successBei einem Fehler wird <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> zurückgegeben..
  </p>
 </div>


  <div class="refsect1 changelog" id="refsect1-function.openssl-pkey-derive-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Beschreibung</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.5.0</td>
      <td>
       The parameter <code class="parameter">key_length</code> is now deprecated.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.openssl-pkey-derive-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="openssl-pkey-derive.example.basic">
    <p><strong>Beispiel #1 <span class="function"><strong>openssl_pkey_derive()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
</span><span style="color: #FF8000">// Load in private key
</span><span style="color: #0000BB">$priv </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_pkey_get_private</span><span style="color: #007700">(</span><span style="color: #DD0000">"-----BEGIN PRIVATE KEY-----
MIICJgIBADCCARcGCSqGSIb3DQEDATCCAQgCggEBAJLxRCaZ933uW+AXmabHFDDy
upojBIRlbmQLJZfigDaSA1f9YOTsIv+WwVFTX/J1mtCyx9uBcz0Nt2kmVwxWuc2f
VtCEMPsmLsVXX7xRUFLpyX1Y1IYGBVXQOoOvLWYQjpZgnx47Pkh1Ok1+smffztfC
0DCNt4KorWrbsPcmqBejXHN79KvWFjZmXOksRiNu/Bn76RiqvofC4z8Ri3kHXQG2
197JGZzzFXHadGC3xbkg8UxsNbYhVMKbm0iANfafUH7/hoS9UjAVQYtvwe7YNiW/
HnyfVCrKwcc7sadd8Iphh+3lf5P1AhaQEAMytanrzq9RDXKBxuvpSJifRYasZYsC
AQIEggEEAoIBAGwAYC2E81Y1U2Aox0U7u1+vBcbht/OO87tutMvc4NTLf6NLPHsW
cPqBixs+3rSn4fADzAIvdLBmogjtiIZoB6qyHrllF/2xwTVGEeYaZIupQH3bMK2b
6eUvnpuu4Ytksiz6VpXBBRMrIsj3frM+zUtnq8vKUr+TbjV2qyKR8l3eNDwzqz30
dlbKh9kIhZafclHfRVfyp+fVSKPfgrRAcLUgAbsVjOjPeJ90xQ4DTMZ6vjiv6tHM
hkSjJIcGhRtSBzVF/cT38GyCeTmiIA/dRz2d70lWrqDQCdp9ArijgnpjNKAAulSY
CirnMsGZTDGmLOHg4xOZ5FEAzZI2sFNLlcw=
-----END PRIVATE KEY-----
"</span><span style="color: #007700">);

</span><span style="color: #FF8000">// Load in public key
</span><span style="color: #0000BB">$pub </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_pkey_get_public</span><span style="color: #007700">(</span><span style="color: #DD0000">"-----BEGIN PUBLIC KEY-----
MIICJDCCARcGCSqGSIb3DQEDATCCAQgCggEBAJLxRCaZ933uW+AXmabHFDDyupoj
BIRlbmQLJZfigDaSA1f9YOTsIv+WwVFTX/J1mtCyx9uBcz0Nt2kmVwxWuc2fVtCE
MPsmLsVXX7xRUFLpyX1Y1IYGBVXQOoOvLWYQjpZgnx47Pkh1Ok1+smffztfC0DCN
t4KorWrbsPcmqBejXHN79KvWFjZmXOksRiNu/Bn76RiqvofC4z8Ri3kHXQG2197J
GZzzFXHadGC3xbkg8UxsNbYhVMKbm0iANfafUH7/hoS9UjAVQYtvwe7YNiW/Hnyf
VCrKwcc7sadd8Iphh+3lf5P1AhaQEAMytanrzq9RDXKBxuvpSJifRYasZYsCAQID
ggEFAAKCAQAiCSBpxvGgsTorxAWtcAlSmzAJnJxFgSPef0g7OjhESytnc8G2QYmx
ovMt5KVergcitztWh08hZQUdAYm4rI+zMlAFDdN8LWwBT/mGKSzRkWeprd8E7mvy
ucqC1YXCMqmIwPySvLQUB/Dl8kgau7BLAnIJm8VP+MVrn8g9gghD0qRCgPgtEaDV
vocfgnOU43rhKnIgO0cHOKtw2qybSFB8QuZrYugq4j8Bwkrzh6rdMMeyMl/ej5Aj
c0wamOzuBDtXt0T9+Fx3khHaowjCc7xJZRgZCxg43SbqMWJ9lUg94I7+LTX61Gyv
dtlkbGbtoDOnxeNnN93gwQZngGYZYciu
-----END PUBLIC KEY-----
"</span><span style="color: #007700">);

</span><span style="color: #FF8000">// Outputs the hex version of the derived key
</span><span style="color: #007700">echo </span><span style="color: #0000BB">bin2hex</span><span style="color: #007700">(</span><span style="color: #0000BB">openssl_pkey_derive</span><span style="color: #007700">(</span><span style="color: #0000BB">$pub</span><span style="color: #007700">,</span><span style="color: #0000BB">$priv</span><span style="color: #007700">));</span></code></pre></div>
    </div>

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


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