How to make X.509 certificate?

10,363

Solution 1

I always use the SelfCert tool from PluralSight. You can download it here. The same pages also give usage and code examples.

Great free tool, can't do without it.

Solution 2

It is nice that you have find that makecert command but perhaps if you would also check makecert documentation you have found where the certificate is stored because it is defined in the paramaters of your command:

  • sr says that certificate will be generated for LocalMachine store location
  • ss says that certificate will be stored in Personal (My) store

The certificate is stored in certificate store so use MMC.exe to find it:

  • Open Start menu
  • In Search / Run type mmc and run it
  • In File menu select Add / Remove snap-in
  • Select Certificates snap-in with scope of Local computer and confirm selection

Now in Personal store for your LocalMachine select certificate called MyServerCert and from context menu select All Tasks > Export. During Exporting check that you want export private key but don't check extended security or private key deletion. You will also have to select path where exported certificate will be stored and password for access to a private key.

From VS command prompt you can also run this command which will do the export for you as well:

certutil.exe -privatekey -p password -exportpfx "MyServerCert" C:\Temp\MyServerCert.pfx 

It should export your certificate with private key to Temp directory and password to certificate will be password.

Share:
10,363
Vero009
Author by

Vero009

I am a student of C# programming school and i love programming too much !!!

Updated on June 04, 2022

Comments

  • Vero009
    Vero009 almost 2 years

    I am trying to make a X.509 certificate. I am using makecert.exe to make this. I use this command to make my X.509 certificate

     makecert.exe -sr LocalMachine -ss My -a sha1 -n CN=MyServerCert -sky exchange –pe
    

    But i don`t know there X.509 certificate is storeing.
    I need to use this X.509 certificate in my c# code. The code is :

      host.Credentials.ServiceCertificate.Certificate = new X509Certificate2("MyServerCert.p12", "password");
    

    But i don`t know what is password and it throw this exception "The system cannot find the file specified."