0

I want to create an X509Certificate2 object in my C# by importing a Certificate which contains private key.

This certificate I have exported from my Database using the following LOC –

BACKUP CERTiFiCATE TestCert TO FiLE = 'C:\Avdhut\TestCert1.cer' WiTH PRiVATE KEY ( FiLE = 'C:\Avdhut\TestCertWithPrivateKey.cer', ENCRYPTiON BY PASSWORD = 'wiND0w5' )

I have the following C# code – X509Certificate2 cert = new X509Certificate2(@"C:\Avdhut\TestCertWithPrivateKey.cer", "wiND0w5"); It however throws an exception stating – CryptographicException was unhandled Cannot find the requested object

Avdhut Vaidya
  • 314
  • 2
  • 13

1 Answers1

0

Apparently, your certificate file is malformed (formatted in PEM) and which is not supported by .NET. Look in this thread for additional information: How do I use a private key in C#? "Cannot find the requested object."

Community
  • 1
  • 1
Crypt32
  • 12,850
  • 2
  • 41
  • 70