I have a been given a private key that turned out to be in pkcs8 format, which I managed to turn into a pem file using the following command:
openssl pkcs8 -inform der -nocrypt -in private.key -out pkey.pem
I now need to convert this to pkcs12 so I can use it in .NET to create an X509 certificate (also I'd like to import it to windows cert manager).
I tried this command:
openssl pkcs12 -export -name myalias -in mycert.crt -inkey pkey.pem -out keystore.p12
however, I don't have the public key, I've tried using the pkey.pem file as the -in arg, but it tells me No certificate matches private key
. If I try without the -in
arg then nothing happens (and I mean nothing, there is a blank row until I press ctrl-c
).
How can I generate the public key from the private key, or convert to pkcs12 without the public key?
The first part of this question, was from the answer here
I found an answer that gave me some hope, which says to run this command (-nocerts):
openssl pkcs12 -export -nocerts -inkey your.private.key.pem -out your.private.key.p12
But when I try to import the file into the windows key store, it says The specified file is empty
when it is importing.
I've also managed to generate a certificate signing request from instructions here, which generated a certificate file, but the command still didn't accept that saying No certificate matches private key
Another answer suggests generating the public key, which I do, but when I use that as the -in
arg it still says No certificate matches private key
, which I don't understand as this public key was generated from the private key using this command: openssl rsa -in privkey.pem -pubout > key.pub
EDIT: I've posted an answer below, but as mentioned I've no way of verifying this information or telling if it works. If anyone has any further information, please let me know.