2024 年日本 PHP 研討會

openssl_csr_export_to_file

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

openssl_csr_export_to_fileCSR 匯出至檔案

說明

openssl_csr_export_to_file(OpenSSLCertificateSigningRequest|字串 $csr, 字串 $output_filename, 布林值 $no_text = true): 布林值

openssl_csr_export_to_file() 函式會將 csr 參數所代表的憑證簽署請求 (CSR),以 PEM 格式儲存至 output_filename 參數所指定名稱的檔案中。

參數

csr

請參閱 CSR 參數 以取得有效值的列表。

output_filename

輸出檔案的路徑。

no_text

選用參數 notext 會影響輸出的詳細程度;如果設為 false,則輸出中會包含額外的人類可讀資訊。 notext 的預設值為 true

返回值

成功時返回 true,失敗時返回 false

更新日誌

版本 說明
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');
?>

參見

新增筆記

使用者貢獻的筆記

此頁面沒有使用者貢獻的筆記。
To Top