5

My knownledge about security is limited so I need some help here.

The Question

I want to Decrypt a .P7M file using its private key (.pem). I would prefer to use OpenSSL for this.

Tried so far

OpenSSL smime -decrypt -in "Secret.p7m" -inkey "Key.pem" > Result.txt 

Error

unable to load signing key file 7548:error:0906D06C:PEM routines:PEM_read_bio:no start line:.\crypto\pem\pem_lib .c:701:Expecting: ANY PRIVATE KEY error in smime**The P7M File** 

Content-Type: application/pkcs7-mime; name="smime.p7m"; smime-type=enveloped-data
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7m"
Content-Description: S/MIME Encrypted Message

BLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLA

2
  • "Cannot seem to get it to work". What command did you use, and what was the result? Any error messages? Commented Jun 4, 2015 at 8:07
  • 1
    Edited post with code sample i used Commented Jun 4, 2015 at 8:22

3 Answers 3

2

Your decryption command is correct.

It seems there's something wrong with your key file. Does it really start with -----BEGIN RSA PRIVATE KEY----- and end with -----END RSA PRIVATE KEY----- (mind the exact number of dashes)? Or is it perhaps DER encoded which requires you to add -keyform DER your decryption command line?

BTW: You can check the integrity of the key itself with openssl rsa -in Key.pem

1
  • Checking the integrity is fine. The output gives me -----BEGIN RSA PRIVATE KEY---- BLABLABALABALBALABALBA -----END RSA PRIVATE KEY----- Commented Jun 4, 2015 at 10:34
1

I have run into this same issue and Lupo's answer is on the right track. You can try converting the key using a command like:

openssl pkcs12 -in <key file.p7m> -out <key_file.pem> -nodes 
1

A *.p7m file is a PKCS#7/CAdES container. If it wraps a PDF, you can extract the embedded PDF without verifying the certificate chain:

Windows/macOS/Linux (OpenSSL): openssl smime -verify -noverify -inform DER -in "document.pdf.p7m" -out "document.pdf"

If the container is valid and the payload is indeed a PDF, the output will be a normal PDF.

Online solution: Disclosure: I’m affiliated with CoolUtils; here’s an online tool that unwraps *.p7m with an embedded PDF in one step: https://www.coolutils.com/online/P7M-to-PDF

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.