(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
openssl_csr_export_to_file — 將 CSR 匯出至檔案
$csr
, 字串 $output_filename
, 布林值 $no_text
= true
): 布林值
openssl_csr_export_to_file() 函式會將 csr
參數所代表的憑證簽署請求 (CSR),以 PEM 格式儲存至 output_filename
參數所指定名稱的檔案中。
版本 | 說明 |
---|---|
8.0.0 |
csr 參數現在接受 OpenSSLCertificateSigningRequest 實例;先前接受的是類型為 OpenSSL X.509 CSR 的 資源。 |
範例 #1 openssl_csr_export_to_file() 範例
<?php
$subject = array(
"commonName" => "example.com",
);
$private_key = openssl_pkey_new(array(
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
));
$csr = openssl_csr_new($subject, $private_key, array('digest_alg' => 'sha384') );
openssl_pkey_export_to_file($private_key, 'example-priv.key');
// 除了主旨之外,CSR 還包含與私鑰對應的公鑰
openssl_csr_export_to_file($csr, 'example-csr.pem');
?>