Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

On Ubuntu, I cannot convert certificate using openssl successfully.

vagrant@dev:/vagrant/keys$ openssl pkcs7 -print_certs -in a.p7b -out a.cer 
unable to load PKCS7 object <blah blah>:PEM
routines:PEM_read_bio:no start line:pem_lib.c:696:Expecting: PKCS7

Have you seen this error before?

share|improve this question
Are you sure the file is a p7b? –  Zoredache Aug 13 '12 at 19:52
Was the file moved between servers or uploaded via FTP? If it is indeed the correct format, it seems as though it may have become corrupted. Try re-transferring the file to the server in binary mode (if using FTP) or re-copy it from the source. –  Garrett Aug 13 '12 at 20:01
I say it's a p7b based on the file's suffix. I re-downloaded it via Firefox, but I still got the same OpenSSL error... –  Kevin Meredith Aug 13 '12 at 20:30
@Kevin What does file a.p7b give you? –  Nic Young Aug 13 '12 at 20:37
@NicYoung - I just get the above error message. No output. –  Kevin Meredith Aug 13 '12 at 20:45

4 Answers 4

up vote 14 down vote accepted

Try this:

$ openssl pkcs7 -inform der -in a.p7b -out a.cer

If it doesn't work, brings to a Windows machine and export follow this guide.

share|improve this answer
That worked. Thank you. –  Kevin Meredith Aug 14 '12 at 14:09

I followed this guide that instructs you to change the header/footer lines from




Then run the command openssl pkcs7 -in foo.modified.crt -print_certs -out foo.certs (where foo.modified.crt is the file that you saved the modified version into). This gave me the same results as running through a Windows certificate export as suggested in other answers.

share|improve this answer
This actually worked for me. Thanks. –  agarcian Jun 27 at 20:00

I had this problem too. I was going to verify a p7b file I copied from a Win7 host.

I found out that gnome keyring can import the certificate. From there it's easy to export to DER

share|improve this answer

quick solution in my case (a lot of files with missing header/footer) :

base64 -d $FILE | openssl pkcs7 -inform DER -print_certs

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.