【问题标题】:How to convert PFX to CRT and PEM using PHP?如何使用 PHP 将 PFX 转换为 CRT 和 PEM?
【发布时间】:2019-11-29 05:29:44
【问题描述】:

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

【问题讨论】:

    标签: php openssl certificate


    【解决方案1】:
    <?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);
    

    【讨论】:

      猜你喜欢
      • 2015-01-30
      • 2023-03-20
      • 2011-06-09
      • 2014-11-26
      • 2013-06-22
      • 2017-01-27
      • 1970-01-01
      • 2020-10-30
      • 2012-04-15
      相关资源
      最近更新 更多