Rick Hodder
Rick Hodder

Reputation: 2252

curl and certificate parameter from .net web request

Previously I asked a question about curl and security certificates, and how to accomplish the equivalent in .net :

cURL request using .NET using security certificate

I'm trying to run the code from a Windows service, which runs under local system (I know its not the best of ideas but I need to have file access)

The service runs under a login that I cannot add certificates to. So I'm wondering if there is a way to accomplish it the way curl does using pem files from a .net webrequest.

Any ideas?

Upvotes: 1

Views: 245

Answers (1)

Rick Hodder
Rick Hodder

Reputation: 2252

Figured it out

I have a PFX file, and it turns out that I can create a certificate from the file if I use X509Certificate2 instead of X509Certificate, and pass the pfx file name, and the password to the constructor of the class:

X509Certificate2 certificate = new X509Certificate2(fullPathToPFXFile, certificatePassword);

req = (HttpWebRequest)WebRequest.Create("www.abc.com");

req.ClientCertificates.Add(cert);

Upvotes: 1

Related Questions