<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.openssl-spki-new.php',
    1 => 'openssl_spki_new',
    2 => 'Generate a new signed public key and challenge',
  ),
  'up' => 
  array (
    0 => 'ref.openssl.php',
    1 => 'OpenSSL Functions',
  ),
  'prev' => 
  array (
    0 => 'function.openssl-spki-export-challenge.php',
    1 => 'openssl_spki_export_challenge',
  ),
  'next' => 
  array (
    0 => 'function.openssl-spki-verify.php',
    1 => 'openssl_spki_verify',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/openssl/functions/openssl-spki-new.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.openssl-spki-new" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">openssl_spki_new</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.6.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">openssl_spki_new</span> &mdash; <span class="dc-title">Generate a new signed public key and challenge</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.openssl-spki-new-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>openssl_spki_new</strong></span>(<span class="methodparam"><span class="attribute"><a href="class.sensitiveparameter.php">#[\SensitiveParameter]</a> </span><span class="type"><a href="class.opensslasymmetrickey.php" class="type OpenSSLAsymmetricKey">OpenSSLAsymmetricKey</a></span> <code class="parameter">$private_key</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$challenge</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$digest_algo</code><span class="initializer"> = <strong><code><a href="openssl.signature-algos.php#constant.openssl-algo-md5">OPENSSL_ALGO_MD5</a></code></strong></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">
   Generates a signed public key and challenge using specified hashing algorithm
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-spki-new-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
     <dt><code class="parameter">private_key</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">private_key</code> should be set to a private key that was
       previously generated by <span class="function"><a href="function.openssl-pkey-new.php" class="function">openssl_pkey_new()</a></span> (or
       otherwise obtained from the other openssl_pkey family of functions).
       The corresponding public portion of the key will be used to sign the
       <abbr title="Certificate Signing Request">CSR</abbr>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">challenge</code></dt>
     <dd>
      <p class="para">
       The challenge associated to associate with the SPKAC
      </p>
     </dd>
    
    
     <dt><code class="parameter">digest_algo</code></dt>
     <dd>
      <p class="para">
       The digest algorithm. See openssl_get_md_method().
      </p>
     </dd>
    
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-spki-new-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a signed public key and challenge string or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
  </p>
 </div>


  <div class="refsect1 errors" id="refsect1-function.openssl-spki-new-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   Emits an <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> level error if an unknown signature algorithm
   is passed via the <code class="parameter">digest_algo</code> parameter.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.openssl-spki-new-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</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> instance now;
       previously, a <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> of type <code class="literal">OpenSSL key</code> was accepted.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.openssl-spki-new-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="openssl_spki_new.example.basic">
   <p><strong>Example #1 <span class="function"><strong>openssl_spki_new()</strong></span> example</strong></p>
   <div class="example-contents"><p>
     Generate a new SPKAC with the default digest (MD5)
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$pkey </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_pkey_new</span><span style="color: #007700">(</span><span style="color: #DD0000">'secret password'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$spkac </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_spki_new</span><span style="color: #007700">(</span><span style="color: #0000BB">$pkey</span><span style="color: #007700">, </span><span style="color: #DD0000">'testing'</span><span style="color: #007700">);<br /><br />if (</span><span style="color: #0000BB">$spkac </span><span style="color: #007700">!== </span><span style="color: #0000BB">NULL</span><span style="color: #007700">) {<br />    echo </span><span style="color: #0000BB">$spkac</span><span style="color: #007700">;<br />} else {<br />    echo </span><span style="color: #DD0000">"SPKAC generation failed"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>The above example will output
something similar to:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">MIICRzCCAS8wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDM3V3sS4o4
mB9dczziRnjGAmSp+JwPrHoYMAFGvDNmZGyiWfU586X4BKs++BAj7e/FsAfno0Hd
hN9FwpCNFSox30L03nQvLYJE7f/WqigwBeMRT7Op/xvFks4sT70xP2HRYv4KqP9a
WRcKU6cFH8VxhFhqM2txEIxZKdFLaL28yT7bEDmcglf4JLDdgNMb9rET1dkgtKE6
dOaJHPGjf1uvnOH4YwkQr7n4sLUR3Kdbh0ZJAFuQVDZulo+LLzxBBkqJJcB6FhF+
oXCdHTKZnqAhpWDz+NXYytAmevab6IYm5TWPWsJUv1YKJA5lg2mXbbloIZlN9Mgc
i9fi03bdw+crAgMBAAEWB3Rlc3RpbmcwDQYJKoZIhvcNAQEEBQADggEBALyUvP/o
pPSoWBlorFyZ2RnGwKf9qMpE0q2IJP7G3oDR4LyK/m933DUiZ+YnqThrH/CWb4Ek
y5I3OCyl3S4wCuU1ibZZwDVwYShr5ELp0J9PEf7qMQZOhNsizoC7k+Czb2xB6hYW
sKfsfTKm3cXBtH3fdgc/Z1Z7VSWnAzYo38snqm72NTf5yFRnrQdphNNXi+kn1zHA
lxXRyFDXHOcYsOnwAWfyXFA4QDHQ0ezz0UoCY8gJXovcZb4GRYqOLUAsF2HcNboy
29WN8VqE29sL9QxVZFlwMcqyoLcNnyw38GvNvAGqSvzzbnEFP2MAQXJVe0H0hdp/
MML5G2iNVgNozAo=</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.openssl-spki-new-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.openssl-spki-verify.php" class="function" rel="rdfs-seeAlso">openssl_spki_verify()</a> - Verifies a signed public key and challenge</span></li>
    <li><span class="function"><a href="function.openssl-spki-export-challenge.php" class="function" rel="rdfs-seeAlso">openssl_spki_export_challenge()</a> - Exports the challenge associated with a signed public key and challenge</span></li>
    <li><span class="function"><a href="function.openssl-spki-export.php" class="function" rel="rdfs-seeAlso">openssl_spki_export()</a> - Exports a valid PEM formatted public key signed public key and challenge</span></li>
    <li><span class="function"><a href="function.openssl-get-md-methods.php" class="function" rel="rdfs-seeAlso">openssl_get_md_methods()</a> - Gets available digest methods</span></li>
    <li><span class="function"><a href="function.openssl-csr-new.php" class="function" rel="rdfs-seeAlso">openssl_csr_new()</a> - Generates a CSR</span></li>
    <li><span class="function"><a href="function.openssl-csr-sign.php" class="function" rel="rdfs-seeAlso">openssl_csr_sign()</a> - Sign a CSR with another certificate (or itself) and generate a certificate</span></li>
   </ul>
  </p>
 </div>


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