How to make X.509 certificate?

六月ゝ 毕业季﹏ 提交于 2019-12-06 11:39:27

问题


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."


回答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.




回答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.



来源:https://stackoverflow.com/questions/7547647/how-to-make-x-509-certificate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!