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

How to convert PFX to CRT and PEM using PHP?

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

<?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);