📄 function.openssl-csr-new.html
字号:
<tr valign="middle"> <td colspan="1" rowspan="1" align="left">digest_alg</td> <td colspan="1" rowspan="1" align="left"><a href="language.types.string.html" class="type string">string</a></td> <td colspan="1" rowspan="1" align="left">default_md</td> <td colspan="1" rowspan="1" align="left">Selects which digest method to use</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">x509_extensions</td> <td colspan="1" rowspan="1" align="left"><a href="language.types.string.html" class="type string">string</a></td> <td colspan="1" rowspan="1" align="left">x509_extensions</td> <td colspan="1" rowspan="1" align="left">Selects which extensions should be used when creating an x509 certificate</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">req_extensions</td> <td colspan="1" rowspan="1" align="left"><a href="language.types.string.html" class="type string">string</a></td> <td colspan="1" rowspan="1" align="left">req_extensions</td> <td colspan="1" rowspan="1" align="left">Selects which extensions should be used when creating a CSR</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">private_key_bits</td> <td colspan="1" rowspan="1" align="left"><a href="language.types.integer.html" class="type integer">integer</a></td> <td colspan="1" rowspan="1" align="left">default_bits</td> <td colspan="1" rowspan="1" align="left">Specifies how many bits should be used to generate a private key</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">private_key_type</td> <td colspan="1" rowspan="1" align="left"><a href="language.types.integer.html" class="type integer">integer</a></td> <td colspan="1" rowspan="1" align="left">none</td> <td colspan="1" rowspan="1" align="left">Specifies the type of private key to create. This can be one of <b><tt>OPENSSL_KEYTYPE_DSA</tt></b>, <b><tt>OPENSSL_KEYTYPE_DH</tt></b> or <b><tt>OPENSSL_KEYTYPE_RSA</tt></b>. The default value is <b><tt>OPENSSL_KEYTYPE_RSA</tt></b> which is currently the only supported key type. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">encrypt_key</td> <td colspan="1" rowspan="1" align="left"><a href="language.types.boolean.html" class="type boolean">boolean</a></td> <td colspan="1" rowspan="1" align="left">encrypt_key</td> <td colspan="1" rowspan="1" align="left">Should an exported key (with passphrase) be encrypted?</td> </tr> </tbody> </colgroup> </table> </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">extraattribs</tt></i></span> <dd> <p class="para"> <i><tt class="parameter">extraattribs</tt></i> is used to specify additional configuration options for the CSR. Both <i><tt class="parameter">dn</tt></i> and <i><tt class="parameter">extraattribs</tt></i> are associative arrays whose keys are converted to OIDs and applied to the relevant part of the request. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the CSR. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Creating a self-signed-certificate</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Fill in data for the distinguished name to be used in the cert<br />// You must change the values of these keys to match your name and<br />// company, or more precisely, the name and company of the person/site<br />// that you are generating the certificate for.<br />// For SSL certificates, the commonName is usually the domain name of<br />// that will be using the certificate, but for S/MIME certificates,<br />// the commonName will be the name of the individual who will use the<br />// certificate.<br /></span><span style="color: #0000BB">$dn </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">"countryName" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"UK"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"stateOrProvinceName" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"Somerset"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"localityName" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"Glastonbury"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"organizationName" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"The Brain Room Limited"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"organizationalUnitName" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"PHP Documentation Team"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"commonName" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"Wez Furlong"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"emailAddress" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"wez@example.com"<br /></span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Generate a new private (and public) key pair<br /></span><span style="color: #0000BB">$privkey </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_pkey_new</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// Generate a certificate signing request<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">$dn</span><span style="color: #007700">, </span><span style="color: #0000BB">$privkey</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// You will usually want to create a self-signed certificate at this<br />// point until your CA fulfills your request.<br />// This creates a self-signed cert that is valid for 365 days<br /></span><span style="color: #0000BB">$sscert </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_csr_sign</span><span style="color: #007700">(</span><span style="color: #0000BB">$csr</span><span style="color: #007700">, </span><span style="color: #0000BB">null</span><span style="color: #007700">, </span><span style="color: #0000BB">$privkey</span><span style="color: #007700">, </span><span style="color: #0000BB">365</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Now you will want to preserve your private key, CSR and self-signed<br />// cert so that they can be installed into your web server, mail server<br />// or mail client (depending on the intended use of the certificate).<br />// This example shows how to get those things into variables, but you<br />// can also store them directly into files.<br />// Typically, you will send the CSR on to your CA who will then issue<br />// you with the "real" certificate.<br /></span><span style="color: #0000BB">openssl_csr_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$csr</span><span style="color: #007700">, </span><span style="color: #0000BB">$csrout</span><span style="color: #007700">) and </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$csrout</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">openssl_x509_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$sscert</span><span style="color: #007700">, </span><span style="color: #0000BB">$certout</span><span style="color: #007700">) and </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$certout</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">openssl_pkey_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$privkey</span><span style="color: #007700">, </span><span style="color: #0000BB">$pkeyout</span><span style="color: #007700">, </span><span style="color: #DD0000">"mypassword"</span><span style="color: #007700">) and </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$pkeyout</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Show any errors that occurred here<br /></span><span style="color: #007700">while ((</span><span style="color: #0000BB">$e </span><span style="color: #007700">= </span><span style="color: #0000BB">openssl_error_string</span><span style="color: #007700">()) !== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br /> echo </span><span style="color: #0000BB">$e </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.openssl-csr-get-subject.html">openssl_csr_get_subject</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.openssl-csr-sign.html">openssl_csr_sign</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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -