Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP将PFX转换为CRT和PEM?_Php_Openssl_Certificate - Fatal编程技术网

如何使用PHP将PFX转换为CRT和PEM?

如何使用PHP将PFX转换为CRT和PEM?,php,openssl,certificate,Php,Openssl,Certificate,如何使用PHP OpenSSL函数将.pfx(PKCS12或.p12)证书转换为.crt和.pem,因此我避免使用公共服务器上不允许的命令行工具。 <?php $res = []; $openSSL = openssl_pkcs12_read($pkcs12, $res, $cert_password); if(!$openSSL) { throw new ClientException("Error: ".openssl_error_string()); } // this is

如何使用PHP OpenSSL函数将.pfx(PKCS12或.p12)证书转换为.crt和.pem,因此我避免使用公共服务器上不允许的命令行工具。


<?php
$res = [];
$openSSL = openssl_pkcs12_read($pkcs12, $res, $cert_password);
if(!$openSSL) {
    throw new ClientException("Error: ".openssl_error_string());
}
// this is the CER FILE
file_put_contents('CERT.cer', $res['pkey'].$res['cert'].implode('', $res['extracerts']));

// this is the PEM FILE
$cert = $res['cert'].implode('', $res['extracerts']);
file_put_contents('KEY.pem', $cert);