Created
May 24, 2018 04:21
-
-
Save sachinsu/3efcc7f6eb0cc215d5edbc20fc2e48a1 to your computer and use it in GitHub Desktop.
Mutual SSL Handshake in C# using HTTPWebRequest and TLS1.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void FromFile() | |
{ | |
// You have to use certificate.p12 or certificate.pfx that contains private key. These extensions represent PKCS#12 standard. There can also be whole certificate chain included in these files | |
var certificatefilePath = "CertificateFile.pfx"; | |
var certpwd = "password"; | |
var URL = "Host_URL"; | |
X509Certificate cert = new X509Certificate(certificatefilePath,certpwd); | |
var webrequest = WebRequest.Create(URL) as HttpWebRequest; | |
ServicePointManager.Expect100Continue = true; | |
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; //TLS 1.2 | |
ServicePointManager.ServerCertificateValidationCallback = ((object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) => true); | |
webrequest.ClientCertificates.Add(cert); | |
webrequest.Credentials = CredentialCache.DefaultNetworkCredentials; | |
webrequest.Method = WebRequestMethods.Http.Get; | |
webrequest.ContentType = "application/json; charset=utf-8"; | |
var responseStream = webrequest.GetResponse().GetResponseStream(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference 1