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

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

1.對(duì)接一個(gè)接口,對(duì)方的接口是java寫(xiě)的,我是php,對(duì)方給了兩個(gè)文件,一個(gè)公鑰.cer,一個(gè)私鑰.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)行驗(yàn)簽?zāi)?/p>

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

openssl_x509_read這個(gè)函數(shù)會(huì)報(bào)錯(cuò)誤
openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate!

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

回答
編輯回答
情已空

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

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

2017年12月8日 21:14