Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No certificate matches private key while generating .p12 file

Tags:

ssl

pkcs#12

I have successfully generated .p12 file but I got a message which is a follows:

C:\OpenSSL-Win32\bin>openssl pkcs12 -export -inkey mykey.key -in exported.pem -out myfile.p12

Loading 'screen' into random state - done No certificate matches private key

Could anyone tell me what is this error all about?

Also, the size of the file myfile.p12 is 0KB and when I tried to open it, I got the following message in a small window with OK button:

`Invalid Public Key Security Object File

This file is invalid for use as the following: Personal Information Exchange `

Please clarify.

Thanks

like image 756
Jack Avatar asked Oct 23 '13 21:10

Jack


People also ask

Does P12 file contain private key?

P12 files are used by various security and encryption programs. P12 keys store a private key that encrypts information in such a way that it can be decrypted only by the corresponding public key. Likewise, data encrypted with the public key can be decrypted only by the private key.


2 Answers

Source

OpenSSL says no certificate matches private key when the certificate is DER-encoded. Just change it to PEM encoding before creating the PKCS#12.

  1. Create key pair : openssl genrsa -out aps_development.key 2048

  2. Create CSR : openssl req -new -sha256 -key aps_development.key -out aps_development.csr

  3. Upload the CSR to developer portal to get the certificate aps_development.cer

  4. Convert the certificate: openssl x509 -inform DER -outform PEM -in aps_development.cer -out aps_development.pem

  5. Build the PKCS#12: openssl pkcs12 -inkey aps_development.key -in aps_development.pem -export -out aps_development.p12

like image 57
Ashish Patil Avatar answered Sep 18 '22 15:09

Ashish Patil


I also had exactly same issue. Below two commands worked like a charm.

cat domain.crt intermediate.crt ca.crt > bundle.crt 

openssl pkcs12 -export -out cert.pfx -inkey key -in bundle.crt
like image 26
vaibhav singhal Avatar answered Sep 18 '22 15:09

vaibhav singhal