You can add a client certificate to a web request like this.
X509Store store = new X509Store("My", StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certificates = store.Certificates.Find(X509FindType.FindBySubjectKeyIdentifier, "XYZ", true);
X509Certificate2 certificate = certificates[0];
HttpWebRequest request = new HttpWebRequest();
request.ClientCertificates.Add(certificate);
Note: WebRequest
is obsolete.
Try using HttpClient instead, which would look something like this
X509Store store = new X509Store("My", StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certificates = store.Certificates.Find(X509FindType.FindBySubjectKeyIdentifier, "XYZ", true);
X509Certificate2 certificate = certificates[0];
WebRequestHandler handler = new WebRequestHandler();
handler.ClientCertificates.Add(certificate);
HttpClient client = new HttpClient(handler);