PHP代码从文件pdf.p7m中提取证书

时间:2019-05-03 07:26:18

标签: php pdf

我需要从扩展名为.p7m的签名PDF文件中提取证书。使用xml.p7m文件没有问题,但是使用pdf.p7m文件却没有问题。按照部分代码(有效)从xml文件中提取证书

// I receive the certified array
function der2smime($file)
{
$to=<<<TXT
MIME-Version: 1.0
Content-Disposition: attachment; filename=“smime.p7m”
Content-Type: application/x-pkcs7-mime; smime-type=signed-data; name=“smime.p7m”
Content-Transfer-Encoding: base64
\n
TXT;
$from=file_get_contents($file);
$to.=chunk_split(base64_encode($from));
return file_put_contents("smime.p7m-b6m",$to);
}

$file = "prova.pdf.p7m";
$filenobom = "pr.pdf.p7m";

$str = file_get_contents($file);

$str = str_replace("\xEF\xBB\xBF",'',$str);

file_put_contents($filenobom, $str);

$response = der2smime($filenobom);

$output = openssl_pkcs7_verify ("smime.p7m-b6m" , 0 , "pippo.crt" ,array("CA.pem"),"CA.pem","prova.pdf");
echo openssl_error_string();
$pemdata="pippo.crt";
$data = openssl_x509_parse(file_get_contents($pemdata));
echo openssl_error_string();
print_r($data);

0 个答案:

没有答案