How to Convert CER File to PFX Using certutil

certutilssl-certificate

I have an SSL certificate from GoDaddy in the following formats

  • CRT
  • PEM
  • P7B

I also downloaded the CSR and private key as text files.

However I need to convert these to PFX format in order to install the certificate on an Azure App Service. I previously tried OpenSSL but it seems that Azure no longer recognizes the encryption method (I shall post the details of these attempts separately).

I have previously used the certutil program to successfully convert a .CER formatted SSL certificate to .PFX format using the syntax

certutil -MergePFX mycert.cer mycert.pfx

as suggested in an answer to the post https://stackoverflow.com/q/9971464/14499007 (note that I previously converted the .CRT file to a .CER file).

However, when I tried to do this again with a new SSL certificate, I get the error

CertUtil: -MergePFX command FAILED: 0x80070002 (WIN32: 2 ERROR_FILE_NOT_FOUND)
CertUtil: The system cannot find the file specified.

The mycert.cer is most definitely in the directory – I actually use tab completion to enter the name. In particular, I can run the command

certutil -dump mycert.cer

and the file is dumped to the screen.

I have that people have had similar errors with other uses of CertUtil, so I am thinking it may be a particular quirk of the program where it needs to be prompted to recognise what directory it is in.

I have tried entering the full path of the file but I get the same error.

It may be that I am not even using the correct method (as I have not used certutil much before).

I would greatly appreciate any help with this as I thought I had found a convenient method of generating PFX files (which turns out to be an unduly complicated process) only to be stumped by this mystery error!

Best Answer

I just figured out the missing piece to this: one must have the private key in the same folder renamed to mycert.key (where mycert is whatever the name of the CER file is). This was the file that could not be found.

The private key in this case had been downloaded from GoDaddy as a text file.