<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Exports a CSR to a file</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.openssl-cipher-iv-length.html">openssl_cipher_iv_length</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.openssl-csr-export.html">openssl_csr_export</a></div> <div class="up"><a href="ref.openssl.html">OpenSSL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.openssl-csr-export-to-file" class="refentry"> <div class="refnamediv"> <h1 class="refname">openssl_csr_export_to_file</h1> <p class="verinfo">(PHP 4 >= 4.2.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">openssl_csr_export_to_file</span> — <span class="dc-title">Exports a CSR to a file</span></p> </div> <div class="refsect1 description" id="refsect1-function.openssl-csr-export-to-file-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>openssl_csr_export_to_file</strong></span> ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$csr</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$outfilename</code></span> [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$notext</code><span class="initializer"> = <strong><code>TRUE</code></strong></span></span> ] )</div> <p class="para rdfs-comment"> <span class="function"><strong>openssl_csr_export_to_file()</strong></span> takes the Certificate Signing Request represented by <code class="parameter">csr</code> and saves it in PEM format into the file named by <code class="parameter">outfilename</code>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.openssl-csr-export-to-file-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <code class="parameter">csr</code></dt> <dd> <p class="para"> See <a href="openssl.certparams.html" class="link">CSR parameters</a> for a list of valid values. </p> </dd> <dt> <code class="parameter">outfilename</code></dt> <dd> <p class="para"> Path to the output file. </p> </dd> <dt> <code class="parameter">notext</code></dt> <dd> <p class="para"> The optional parameter <code class="parameter">notext</code> affects the verbosity of the output; if it is <strong><code>FALSE</code></strong>, then additional human-readable information is included in the output. The default value of <code class="parameter">notext</code> is <strong><code>TRUE</code></strong>. </p> </dd> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.openssl-csr-export-to-file-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 examples" id="refsect1-function.openssl-csr-export-to-file-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-956"> <p><strong>Example #1 openssl_csr_export_to_file() example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$subject </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">"commonName" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"example.com"</span><span style="color: #007700">,<br />);<br /></span><span style="color: #0000BB">$private_key </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_pkey_new</span><span style="color: #007700">(array(<br /> </span><span style="color: #DD0000">"private_key_bits" </span><span style="color: #007700">=> </span><span style="color: #0000BB">2048</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"private_key_type" </span><span style="color: #007700">=> </span><span style="color: #0000BB">OPENSSL_KEYTYPE_RSA</span><span style="color: #007700">,<br />));<br /></span><span style="color: #0000BB">$csr </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_csr_new</span><span style="color: #007700">(</span><span style="color: #0000BB">$subject</span><span style="color: #007700">, </span><span style="color: #0000BB">$private_key</span><span style="color: #007700">, array(</span><span style="color: #DD0000">'digest_alg' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'sha384'</span><span style="color: #007700">) );<br /></span><span style="color: #0000BB">openssl_pkey_export_to_file</span><span style="color: #007700">(</span><span style="color: #0000BB">$private_key</span><span style="color: #007700">, </span><span style="color: #DD0000">'example-priv.key'</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// Along with the subject, the CSR contains the public key corresponding to the private key<br /></span><span style="color: #0000BB">openssl_csr_export_to_file</span><span style="color: #007700">(</span><span style="color: #0000BB">$csr</span><span style="color: #007700">, </span><span style="color: #DD0000">'example-csr.pem'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.openssl-csr-export-to-file-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><span class="function"><a href="function.openssl-csr-export.html" class="function" rel="rdfs-seeAlso">openssl_csr_export()</a> - Exports a CSR as a string</span></li> <li class="member"><span class="function"><a href="function.openssl-csr-new.html" class="function" rel="rdfs-seeAlso">openssl_csr_new()</a> - Generates a CSR</span></li> <li class="member"><span class="function"><a href="function.openssl-csr-sign.html" 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><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.openssl-cipher-iv-length.html">openssl_cipher_iv_length</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.openssl-csr-export.html">openssl_csr_export</a></div> <div class="up"><a href="ref.openssl.html">OpenSSL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>