openssl_pkcs12_export
(PHP 5 >= 5.2.2, PHP 7, PHP 8)
openssl_pkcs12_export — 将 PKCS#12 兼容证书存储文件导出到变量
说明
openssl_pkcs12_export(
OpenSSLCertificate|string
string
#[\SensitiveParameter] OpenSSLAsymmetricKey|OpenSSLCertificate|array|string
#[\SensitiveParameter] string
array
): bool
OpenSSLCertificate|string
$certificate
,string
&$output
,#[\SensitiveParameter] OpenSSLAsymmetricKey|OpenSSLCertificate|array|string
$private_key
,#[\SensitiveParameter] string
$passphrase
,array
$options
= []): bool
openssl_pkcs12_export() 以 PKCS#12 文件格式将 certificate
导入到名为 output
的字符串变量中。
参数
更新日志
版本 | 说明 |
---|---|
8.0.0 |
certificate 现在接受 OpenSSLCertificate
实例;之前接受类型 OpenSSL X.509 CSR 的 resource。
|
8.0.0 |
private_key 现在接受 OpenSSLAsymmetricKey
或 OpenSSLCertificate 实例;之前接受类型 OpenSSL key
或 OpenSSL X.509 的 resource。
|
+添加备注
用户贡献的备注 4 notes
simoncpu was here ¶
14 years ago
If your certificate is not password-protected, just use null or a blank string. Otherwise, this function won't work.
Robert ¶
10 years ago
If you need to provide multiple additional certificates, the 'extracerts' argument needs to be an array with one certificate per element:
<?php
$args = array(
'extracerts' => array(
0 => '-----BEGIN CERTIFICATE----- cert1 ...',
1 => '-----BEGIN CERTIFICATE----- cert2 ...',
// ...
)
);
?>
You can use this to prepare a PEM.
<?php
$pemChain = '...';
preg_match_all('/(-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----)/si', $pemChain, $matches);
$args = array('extracerts' => $matches[0]);
openssl_pkcs12_export($signed_csr, $cerificate_out, $private_key_resource, $passphrase, $args);
?>
ismael at privasy dot org ¶
10 years ago
in order to export a private key to pkcs12 format, the input certificate must contain both private and associated public key in PEM format ,
-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
else this function might return the following error "openssl_pkcs12_export(): cannot get cert from parameter 1"
Anonymous ¶
11 years ago
If you want to include CA-Certificates in the PKCS12 it can be accomplished by using the $args parameter.
<?php
$args = array(
'extracerts' => $CAcert,
'friendly_name' => 'My signed cert by CA certificate'
);
openssl_pkcs12_export($signed_csr, $cerificate_out, $private_key_resource, $passphrase, $args);
?>
备份地址:http://www.lvesu.com/blog/php/function.openssl-pkcs12-export.php