W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
openssl_csr_sign — 用另一個證書簽署 CSR(或者本身)并且生成一個證書
openssl_csr_sign(
OpenSSLCertificateSigningRequest|string $csr,
OpenSSLCertificate|string|null $ca_certificate,
OpenSSLAsymmetricKey|OpenSSLCertificate|array|string $private_key,
int $days,
?array $options = null,
int $serial = 0
): OpenSSLCertificate|false
openssl_csr_sign() 從給定的 CSR 生成 x509 證書。
注意: 必須安裝有效的 openssl.cnf 以保證此函數(shù)正確運(yùn)行。參考有關(guān)安裝的說明以獲得更多信息。
csr
由 openssl_csr_new() 函數(shù)生成的 CSR。 也可以是由類似file://path/to/csr格式指定的指向 PEM 編碼的 CSR 路徑,或者是一個由openssl_csr_export()函數(shù)生成的字符串。
ca_certificate
生成的證書將由ca_certificate
簽名。 如果ca_certificate
為 null
, 生成的證書將是自簽名證書。
private_key
private_key
是 ca_certificate
證書對應(yīng)的私鑰。
days
days
指定生成的證書在幾天內(nèi)有效的時間長度。
options
可以通過 options
確定 CSR 簽名。 查看 openssl_csr_new() 方法獲取 options
的更多相關(guān)信息。
serial
可選的發(fā)行證書編號。如果沒有指定默認(rèn)值為0.
成功時返回 OpenSSLCertificate,失敗則返回 false。
版本 | 說明 |
---|---|
8.0.0 | 成功時,此函數(shù)現(xiàn)在返回 OpenSSLCertificate 實例;之前返回類型 OpenSSL X.509 的 resource。 |
8.0.0 | csr 現(xiàn)在接受 OpenSSLCertificateSigningRequest 實例;之前接受類型 OpenSSL X.509 CSR 的 resource。 |
8.0.0 | ca_certificate 現(xiàn)在接受 OpenSSLCertificate 實例;之前接受類型 OpenSSL X.509 的 resource。 |
8.0.0 | private_key 現(xiàn)在接受 OpenSSLAsymmetricKey 或 OpenSSLCertificate 實例;之前接受類型 OpenSSL key 或 OpenSSL X.509 的 resource。 |
示例 #1 openssl_csr_sign() 示例——簽署 CSR(如何實現(xiàn)自己的 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, $privkey, 365, 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";
}
?>
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: