Search code examples
c#sslhttpwebrequest

HttpWebRequest Add SSL .Key-File to WebRequest


I need to make request to a secure server. In order to authenticate in postman, I send over a .cer and .key + password

postman settings that work

But how can I add .key + password to a WebRequest in C#?

X509Certificate2 certificate = new X509Certificate2("~/Cert/mykey-wru.key", "PASSWORD");

...doenst work...


Solution

  • My answer is combinde with creating the suggestes .pfx file and adding the cert to the local machine store.

    than i needed to read them from there in order to get a seure ssl connection

    foreach (X509Certificate2 certificate in store.Certificates)
                {
                    if (certificate.FriendlyName.Contains("mycert"))
                        request.ClientCertificates.Add(certificate);
                }