牛牛在线工具

openssl_csr_export_to_file()

收录 8868 个 PHP 函数,含用途说明与用法示例。

openssl_csr_export_to_file()

将CSR(证书签名请求)导出到文件中

函数名称:openssl_csr_export_to_file() 函数描述:将CSR(证书签名请求)导出到文件中。 适用版本:PHP 4 >= 4.2.0, PHP 5, PHP 7 语法:openssl_csr_export_to_file(string $csr, string $outfilename [, bool $notext = true]) : bool 参数: $csr:CSR字符串,通常使用openssl_csr_new()函数生成。 $outfilename:输出文件的路径和名称。 $notext(可选):如果设置为true(默认值),则在输出文件中不包括任何文本信息。 返回值: 导出成功时返回true,否则返回false。 示例: // 生成CSR $privateKey = openssl_pkey_new(); $dn = array( "countryName" => "US", "stateOrProvinceName" => "California", "localityName" => "San Francisco", "organizationName" => "Example Company", "organizationalUnitName" => "IT Department", "commonName" => "www.example.com", "emailAddress" => "info@example.com" ); $csr = openssl_csr_new($dn, $privateKey); // 导出CSR到文件 $outfilename = "/path/to/csr.csr"; $result = openssl_csr_export_to_file($csr, $outfilename); if ($result) { echo "CSR导出成功!"; } else { echo "CSR导出失败!"; } 在上面的示例中,我们首先使用openssl_pkey_new()函数生成一个私钥,然后使用openssl_csr_new()函数生成一个CSR。最后,我们使用openssl_csr_export_to_file()函数将CSR导出到指定的文件。如果导出成功,将输出"CSR导出成功!",否则输出"CSR导出失败!"。请确保指定的输出文件路径有写入权限。