3

Anyone know how to create a X509Certificate2 with a private key in .net core, there is no property X509Certificate2.PrivateKey which I can set?

I have the following code

byte[] rawData = ....; var x509Certificate2 = new X509Certificate2(rawData.ToArray(), "XXXX"); bool hasPK = x509Certificate2.HasPrivateKey; // is false

How do I add my PK to the certificate above so that I can pass it into my IdentityServer 4 signing mechanism using services.AddIdentityServer().AddSigningCredential(x509Certificate2);

Any help on either topic is appreciated

Ruskin
  • 1,504
  • 13
  • 25
  • Possible duplicate of [.NET Standard - Merge a certificate and a private key into a .pfx file programmatically](https://stackoverflow.com/questions/44465574/net-standard-merge-a-certificate-and-a-private-key-into-a-pfx-file-programma) – bartonjs Jul 05 '17 at 05:45
  • That's using a preview version of a technology, is there no way to do this with the current released version (.net core 1.1)? – Ruskin Jul 05 '17 at 05:49
  • No, not using framework types. You need them pre-associated in a PFX. Windows NetFX, BouncyCastle, OpenSSL, etc. – bartonjs Jul 05 '17 at 05:50

1 Answers1

-1

Probably you want to have a look at this answered question first: How would I generate the Identity Server signing certificate

Then you will find that makecert is obsolete. Instead you could use PowerShell's: New-SelfSignedCertificate or maybe an extension/helper of that: New-SelfSignedCertificateEx

Once the certificate is generated, you could load it into the Identity Server as described above.

Learner
  • 3,297
  • 4
  • 37
  • 62