Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
I have to do an API request having AES algorithm with SHA256 with private key to sign payload data. While doing this i'm getting an exception
"The request was aborted: Could not create SSL/TLS secure channel."

In windows log it is showing that
An SSL 3.0 connection request was received from a remote client application, but none of the cipher suites supported by the client application are supported by the server. The TLS connection request has failed.


What I have tried:

ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;

    var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://ipaddress/method/");
    httpWebRequest.ContentType = "application/json";

    httpWebRequest.Method = WebRequestMethods.Http.Post; //POST
    string resourePath = "test/123/balance/";
    string requestBody = "";
    string secretWord = "xxxx123";
    string header = "api-request-channelMid";

    string payLoadString = httpWebRequest.Method.ToString() + resourePath + requestBody + secretWord + header;
    byte[] payLoadBytes = Encoding.UTF8.GetBytes(payLoadString);

    RSAParameters publicKey;
    RSAParameters privateKey;

    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048);
    rsa.PersistKeyInCsp = false;
    publicKey = rsa.ExportParameters(false);
    privateKey = rsa.ExportParameters(true);

    byte[] signature = rsa.SignData(payLoadBytes, "SHA256");
    string signedData = Convert.ToBase64String(signature);

    using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
    {
        var serializer = new JavaScriptSerializer();
        string json = "";

        httpWebRequest.Headers.Add("Signature", signedData);
        streamWriter.Write(json);
        streamWriter.Flush();
        streamWriter.Close();
    }

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;

    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
    {
        var result = streamReader.ReadToEnd();
    }
Posted
Updated 23-Jan-17 2:40am
v5
Comments
Richard Deeming 23-Jan-17 14:16pm    
Most servers have disabled SSL3 and TLS1 due to security vulnerabilities. Try using TLS1.1 or 1.2 instead:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;

If that doesn't work, you'll need to check the people who host the API to see which protocols and ciphers they support.
normalsoft 24-Jan-17 3:59am    
Thanks for the reply. I'll check with them regarding this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900