鍍金池/ 問答/PHP  iOS  網(wǎng)絡(luò)安全/ php 如何獲取 公鑰鑰格式為cer,私鑰格式為pfx的證書

php 如何獲取 公鑰鑰格式為cer,私鑰格式為pfx的證書

1.對接一個接口,對方的接口是java寫的,我是php,對方給了兩個文件,一個公鑰.cer,一個私鑰.pfx,
我用openssl_pkcs12_read() 讀取pfx進(jìn)行簽名.

openssl_pkcs12_read(file_get_contents('./private.pfx'), $certs, "sft12#");
if(!$certs) exit(0);
openssl_sign($data, $signature, $certs['pkey']);
$signature = base64_encode($signature);

該怎么讀取.cer進(jìn)行驗簽?zāi)?/p>

$cer_key = file_get_contents('./public.cer'); 
 $cer = openssl_x509_read($cer_key);

openssl_x509_read這個函數(shù)會報錯誤
openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate!

用openssl_x509_read 應(yīng)該是不對的,那應(yīng)該怎么做呢.還是說用openssl命令轉(zhuǎn)換成pem呢! 希望得到指導(dǎo)
x509 -inform der -in test.cer -out test.pem

回答
編輯回答
情已空

pfx后綴證書(私鑰+公鑰)、cer證書(僅有公鑰)
openssl_pkcs12_read(file_get_contents('./private.pfx'), $certs, "sft12#");

print_r([
$certs['cert'],
$certs['pkey']
]);

2017年12月8日 21:14