先临时记个代码
//得到cer(cem编码)的内容
function verifyReturn($data, $signature, $filePath)
{
//shell:openssl x509 -in TrustPay.cer -inform der -text -noout
$certificateCAcerContent = file_get_contents($filePath);
$certificateCApemContent = ‘-----BEGIN CERTIFICATE-----‘ . PHP_EOL
. chunk_split(base64_encode($certificateCAcerContent), 64, PHP_EOL)
. ‘-----END CERTIFICATE-----‘ . PHP_EOL;
$pubkeyid = openssl_get_publickey($certificateCApemContent);
$cerList = openssl_x509_parse($certificateCApemContent);
//有需要可以加入签名和数据,这里只是需要读取证书内容,所以第一个和第二个参数不需要
return $cerList;
}
$cerFile = "C:\Users\Administrator\aaa.cer";
var_dump(verifyReturn(‘‘, ‘‘, $cerFile));
//读取pfx
$cerContent = file_get_contents("C:\Users\Administrator.DESKTOP-4PF1LET\Desktop\cer.pfx");
$result = openssl_pkcs12_read($cerContent, $cer, "11");
if (!$result) {
echo "证书无法读取,请检查证书路径、文件名以及密码是否正确";
}
var_dump(openssl_x509_parse($cer[‘cert‘]));