PHP如何解析pkcs7签名Blob? [英] PHP How to parse pkcs7 signature blob?

查看:105
本文介绍了PHP如何解析pkcs7签名Blob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PKCS7签名,可以从中获取解析的内容

I have a PKCS7 signature which i can get parsed contents from with

openssl pkcs7 -inform DER -in signature.pkcs7 -print_certs -text

但是如何用PHP openssl函数归档相同的输出?

But how do archieve the same output with PHPs openssl functions?

编辑.我成功使用以下功能创建了正确的PEM文件:

Edit. I succeeded in creating a correct PEM file with the following function:

function der2pem($der_data, $type="CERTIFICATE") {
   $pem = chunk_split(base64_encode($der_data), 64, "\n");
   $pem = "-----BEGIN $type-----\n".$pem."-----END $type-----\n";
   return $pem;
}
$data = der2pem($der_data, "PKCS7");

但是,使用PHP手册中提到的任何功能解析数据都不成功.它可以通过openssl与

Im not however successfull in parsing the data with any of the functions mentioned in the PHP manual. It works using openssl with:

openssl pkcs7 -inform PEM -in signature.pkcs7 -print_certs -text

推荐答案

不幸的是,我相信没有简单的解决方案.如果要在PHP中解析PKCS#7 DER编码的签名,则需要一些ASN.1解析器. PHP中的OpenSSL函数无法执行此操作.

Unfortunatelly, I believe there is not simple solution. If you want to parse PKCS#7 DER encoded signature in PHP, you need some ASN.1 parser. OpenSSL functions in PHP are not capable to do it.

尝试使用一些引用的解析器解码DER数据.如果有任何解析器可以工作,则您应该能够查看和提取所需的信息.第一步,您可以尝试phpseclib项目中的在线解析器.

Try to decode your DER data with some of referenced parsers. If any parser will work, you should be able to see and extract required information. As first step, you can try online parser from phpseclib project.

http://phpseclib.sourceforge.net/x509/asn1parse.php

这篇关于PHP如何解析pkcs7签名Blob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆