= 4.2.0, PHP 5, PHP 7, PHP 8)openssl_csr_sign — 用另一個(gè)證書簽署 CSR (或者本身) 并且生成一個(gè)證書說明openssl_csr_sign( mixed $csr, mixed $cacer">

openssl_csr_sign

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

openssl_csr_sign用另一個(gè)證書簽署 CSR (或者本身) 并且生成一個(gè)證書

說明

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

openssl_csr_sign() 從給定的 CSR 生成一個(gè)x509證書資源

注意: 必須安裝有效的 openssl.cnf 以保證此函數(shù)正確運(yùn)行。參考有關(guān)安裝的說明以獲得更多信息。

參數(shù)

csr

openssl_csr_new()函數(shù)生成的CSR. 也可以是由類似file://path/to/csr格式指定的指向PEM編碼的CSR路徑,或者是一個(gè)由openssl_csr_export()函數(shù)生成的字符串。

cacert

生成的證書將由cacert簽名。 如果cacertnull, 生成的證書將是自簽名證書。

priv_key

priv_keycacert證書對(duì)應(yīng)的私鑰。

days

days 指定生成的證書在幾天內(nèi)有效的時(shí)間長度。

configargs

你可以通過configargs確定CSR簽名。 查看openssl_csr_new() 方法獲取 configargs的更多相關(guān)信息。

serial

可選的發(fā)行證書編號(hào)。如果沒有指定默認(rèn)值為0.

返回值

成功,返回一個(gè) x509 證書資源,失敗則返回 false .

范例

示例 #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";
}
?>