how to create a completely new x509Certificate2 in .net?

后端 未结 6 1811
忘了有多久
忘了有多久 2020-12-14 08:07

I google it from web, find many samples to generate a new x509Certificate2 from a file in .net, but there is no one sample to show how to generate a completely new x509Certi

6条回答
  •  孤街浪徒
    2020-12-14 08:35

    You can use PINVOKE to call into Crypt32 to create a self signed certificate. There is some sample code available which will generate one and put it in the certificate store for you.

    There's also Keith Brown's certificate generator, which is written in managed code and has a library you can use.

    Alternatively you can just use BouncyCastle using the Org.BouncyCastle.X509.X509V3CertificateGenerator and the use the utility methods in Org.BouncyCastle.Security.DotNetUtilities and call ToX509Certificate().

    If you want to create a request and have it signed by a CA that's actually easier in .NET, as most of those classes can be imported as COM interop DLLs. But that's a whole other question.

提交回复
热议问题