user2191209
user2191209

Reputation: 125

X509 Cannot find requested object

I have a certificate.cer file in the same directory (copy if newer) with the RSA key inside yet when I try:

string certificateFile = Environment.CurrentDirectory + "\\Certificate.cer";
X509Certificate2 x509 = new X509Certificate2(X509Certificate.CreateFromCertFile(certificateFile));

I get the same

"Cannot find requested object"

error. How can I not get the error?

Upvotes: 9

Views: 12211

Answers (1)

aaroncatlin
aaroncatlin

Reputation: 3271

You can just pass the filename into the new() method.

Try:

X509Certificate2 x509 = new X509Certificate2(certificateFile);

If the certificate has a password, you must also supply this (where password is a String):

X509Certificate2 x509 = new X509Certificate2(certificateFile, password);

Upvotes: 2

Related Questions