How to make X.509 certificate?

I am trying to make an X.509 certificate. For this I use makecert.exe. 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 do not know if there is an X.509 certificate.
I need to use this X.509 certificate in my C # code. The code:

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

But I do not know what a password is, and it throws this exception. "The system cannot find the specified file."

+2
source share
2 answers

I always use the PluralSight SelfCert tool. You can download it here . Examples of usage and code are provided on the same pages.

A great free tool, can not do without it.

+8
source

It's good that you found the makecert command, but maybe if you also checked the makecert documentation , you found where the certificate is stored, because it is defined in the parameters of your command:

  • sr says certificate will be created for LocalMachine store location
  • ss says the certificate is stored in the Personal ( My ) store

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

  • Open Start Menu
  • In search / launch mode mmc and run it
  • From the File menu, select Add / Remove Snap-In
  • Select the Certificates snap-in with the local computer area and confirm.

Now in the Personal store for your LocalMachine certificate, select MyServerCert and select "All Tasks> Export" in the context menu. During the export, verify that you want to export the private key, but do not check the advanced security or private key deletion. You will also need to choose the path where the exported certificate will be stored, and the password for accessing the private key.

From the VS command line, you can also run this command, which will also export for you:

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

It must export the private key certificate to the Temp directory and password for the password certificate.

+5
source

All Articles