openssl_csr_sign

(PHP 4 >= 4.2.0, PHP 5, PHP 7)

openssl_csr_sign锟斤拷锟斤拷一锟斤拷证锟斤拷签锟斤拷 CSR (锟斤拷锟竭憋拷锟斤拷) 锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷证锟斤拷

说锟斤拷

openssl_csr_sign ( mixed $csr , mixed $cacert , mixed $priv_key , int $days [, array $configargs [, int $serial = 0 ]] ) : resource

openssl_csr_sign() 锟接革拷锟斤拷锟斤拷 CSR 锟斤拷锟斤拷一锟斤拷x509证锟斤拷锟斤拷源

Note: 锟斤拷锟诫安装锟斤拷效锟斤拷 openssl.cnf 锟皆憋拷证锟剿猴拷锟斤拷锟斤拷确锟斤拷锟叫★拷锟轿匡拷锟叫癸拷锟斤拷装锟斤拷说锟斤拷锟皆伙拷酶锟斤拷锟斤拷锟较拷锟�

锟斤拷锟斤拷

csr

锟斤拷openssl_csr_new()锟斤拷锟斤拷锟斤拷锟缴碉拷CSR. 也锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷file://path/to/csr锟斤拷式指锟斤拷锟斤拷指锟斤拷PEM锟斤拷锟斤拷锟紺SR路锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷openssl_csr_export()锟斤拷锟斤拷锟斤拷锟缴碉拷锟街凤拷锟斤拷锟斤拷

cacert

锟斤拷锟缴碉拷证锟介将锟斤拷cacert签锟斤拷锟斤拷 锟斤拷锟�cacertNULL, 锟斤拷锟缴碉拷证锟介将锟斤拷锟斤拷签锟斤拷证锟介。

priv_key

priv_key锟斤拷cacert证锟斤拷锟接︼拷锟剿皆匡拷锟�

days

days 指锟斤拷锟斤拷锟缴碉拷证锟斤拷锟节硷拷锟斤拷锟斤拷锟斤拷效锟斤拷时锟戒长锟饺★拷

configargs

锟斤拷锟斤拷锟酵拷锟�configargs确锟斤拷CSR签锟斤拷锟斤拷 锟介看openssl_csr_new() 锟斤拷锟斤拷锟斤拷取 configargs锟侥革拷锟斤拷锟斤拷锟斤拷锟较拷锟�

serial

锟斤拷选锟侥凤拷锟斤拷证锟斤拷锟脚★拷锟斤拷锟矫伙拷锟街革拷锟侥拷锟街滴�0.

锟斤拷锟斤拷值

锟缴癸拷锟斤拷锟斤拷锟斤拷一锟斤拷 x509 证锟斤拷锟斤拷源锟斤拷失锟斤拷锟津返伙拷 FALSE .

锟斤拷锟斤拷

Example #1 openssl_csr_sign() example - signing a CSR (how to implement your own CA)

<?php
// Let's assume that this script is set to receive a CSR that has
// been pasted into a textarea from another page
$csrdata $_POST["CSR"];

// We will sign the request using our own "certificate authority"
// certificate.  You can use any certificate to sign another, but
// the process is worthless unless the signing certificate is trusted
// by the software/users that will deal with the newly signed certificate

// We need our CA cert and its private key
$cacert "file://path/to/ca.crt";
$privkey = array("file://path/to/ca.key""your_ca_key_passphrase");

$usercert openssl_csr_sign($csrdata$cacert$privkey365, array('digest_alg'=>'sha256') );

// Now display the generated certificate so that the user can
// copy and paste it into their local configuration (such as a file
// to hold the certificate for their SSL server)
openssl_x509_export($usercert$certout);
echo 
$certout;

// Show any errors that occurred here
while (($e openssl_error_string()) !== false) {
    echo 
$e "\n";
}
?>