PHP How to parse pkcs7 signature blob?

后端 未结 2 784
慢半拍i
慢半拍i 2021-01-05 17:48

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

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

But how

相关标签:
2条回答
  • 2021-01-05 18:10

    What about this solution :)

    <?php
        $result = shell_exec('openssl pkcs7 -inform DER -in signature.pkcs7 -print_certs -text');
        var_dump ($result);
        // you can use preg_match() if you want to parse something specific 
    
    0 讨论(0)
  • 2021-01-05 18:12

    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.

    Do any PHP libraries exist for parsing ASN.1 or generating PHP code based on it?

    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

    0 讨论(0)
提交回复
热议问题