0

The Azure portal will not let me add a Cer file. I found a post saying you can type the name in, you can only do this from the open dialogue and it does not work

So I am trying to convert the file using code I have placed in my Global.asax. I have copied the CER file into my temp directory off the root of C drive

Here is the code and Error I get :

    string file = @"C:\temp\SVRSecureG3.cer";
    var cert = System.Security.Cryptography.X509Certificates.X509Certificate2.CreateFromCertFile(file);

    // Error occurs on the line below, I get : {"Unable to cast object of type 'System.Security.Cryptography.X509Certificates.X509Certificate' to type 'System.Security.Cryptography.X509Certificates.X509Certificate2'."}
    var bytes = ((System.Security.Cryptography.X509Certificates.X509Certificate2)cert).Export(System.Security.Cryptography.X509Certificates.X509ContentType.Pfx, "p"); 

    var fs = File.Create(@"C:\temp\SVRSecureG3.pfx");

    using (fs)
    {
        fs.Write(bytes, 0, bytes.Length);
        fs.Flush();
    }
John
  • 1,459
  • 4
  • 21
  • 45

1 Answers1

1

I would actually just recommend converting your .cer to a .pfx. Use OpenSSL to do this, I have done this numerous times to upload certificates to Azure.

Download

http://slproweb.com/products/Win32OpenSSL.html

Usage

create a pfx file from a .cer and a .pem file

Community
  • 1
  • 1
Adam
  • 16,089
  • 6
  • 66
  • 109
  • Thanks for the reply, we don't have a password as its a third party – John Jun 12 '14 at 06:25
  • But you create the password for the PFX you don't need to get it from someone. – Adam Jun 12 '14 at 08:53
  • Yes he will, however without the private key he can't install a certificate anyway. He needs it or can't install the certificate. – Adam Jun 12 '14 at 13:11