C# – Generate X.509 certificate key pair and signing request (CSR) in C#

c++csrx509

How do you generate a X.509 public and private key pair and a signing request (CSR file) to be sent to a CA for signing in C#?

Best Solution

Generating a RSA key-pair is easy:

// Generate a 2048 bit RSA keypair
RSA keypair = new RSACryptoServiceProvider(2048);

Unfortunately .NET has no support for generating certificate-requests. Your best bet is probably to interface with the COM-component CEnroll. You should use the CreatePKCS10-method.

Related Question