Hi all
I need to get token in c# help using cipher suite.
I need to create .net console app code to user Cipher Suites available in 2012 R2
Hi all
I need to get token in c# help using cipher suite.
I need to create .net console app code to user Cipher Suites available in 2012 R2
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jithu ThomasPosted Dec 13, 2023, 9:51 PM
using System;
using System.Net;
class Program
{
static void Main()
{
// Replace with the actual URL you want to connect to
string targetUrl = "https://example.com";
try
{
// Set the security protocol to TLS 1.2 (compatible with 2012 R2)
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Replace with the Cipher Suites you want to use
string[] cipherSuites = { "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" };
// Set the Cipher Suites
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Disable older protocols for enhanced security
ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls;
ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3;
// Set the Cipher Suites
ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl2;
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
// Create a web request
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(targetUrl);
// Set the Cipher Suites on the request
request.CipherSuites = cipherSuites;
// Perform the request
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
// Process the response if needed
Console.WriteLine("Response Status: " + response.StatusCode);
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}
The code sets the security protocol to TLS 1.2 and specifies two Cipher Suites (
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384andTLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256). You should replace these values with the Cipher Suites that you want to use.