Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

openssl pkcs7 - get the data only

Tags:

openssl

pkcs#7

I have a PKCS7-signed file in DER format, pkcs_input, and I want to extract the data out of it.

Running the command: openssl pkcs7 -in pkcs_input -inform DER -print results in the following output:

PKCS7:
  type: pkcs7-signedData (1.2.840.113549.1.7.2)
  d.sign:
    version: 1
    md_algs:
        [...]
    contents:
      type: pkcs7-data (1.2.840.113549.1.7.1)
      d.data:
        0000 - [hex data]   [ASCII data]
        [...]
    cert:
        cert_info:
          [...]

And then, in order to get the data (marked with [ASCII data]) out of this output, I have to manually parse the entire output.

Is there any other way to get the data only?

like image 257
Bolchojeet Avatar asked Oct 31 '25 21:10

Bolchojeet


1 Answers

The pkcs7 command is mostly intended to give informations on the pkcs7 structure and the certificates it contains.
So to extract the content inside the pkcs7, you need to use instead the smime command :

 openssl smime -verify -CAfile chain_root.pem -in pkcs_input -inform DER -out content

If for some reason, you wish to extract the content without verification, you need to add -noverify after -verify:

 openssl smime -verify -noverify -in pkcs_input -inform DER -out content
   
like image 180
jmd Avatar answered Nov 04 '25 00:11

jmd