2

我正在尝试使用 PHP 获取证书的所有者信息。我有.p12文件,当尝试使用openssl PHP函数读取信息时:

if (getenv('HTTPS')=='on'){ 
           $cert=$_SERVER['SSL_CLIENT_CERT']; 
         }else{ 
            $fname = "certname.p12";
            $f = fopen($fname, "r"); 

            $cert = fread($f, filesize($fname)); 
            fclose($f); 
         }  
        $certdata = array();
        $pass = "pass";

        openssl_pkcs12_read($cert, $certdata, $pass);

        print_r($certdata);

我获得了三个加密字段:

['cert']
['pkey']
['extracerts']['0']

例如,如何以纯文本格式阅读电子邮件字段?

谢谢

4

2 回答 2

3

通过以下方式解决了它:

 openssl_pkcs12_read($cert, $certdata, $pass);

 $certdata= openssl_x509_parse($certdata['cert'],0);

谢谢大家

于 2016-04-14T11:49:04.697 回答
0

我有其他方法来获取证书值

if (openssl_pkcs12_read($almacén_cert, $info_cert, $request->password))
    {
        $pkey = $info_cert['pkey'];  //private key
        $cert = $info_cert['cert'];  //public key

        $certdata= openssl_x509_parse($info_cert['cert'],0);

        return  $certdata; // base64_decode($info_cert['extracerts'][0]);


    } else {
        return "Error.";
    }

我在 Laravel 中使用了这个

于 2020-03-30T23:43:46.123 回答