C# - Could not create SSL/TLS secure channel - Authentication Issues

CipherIS
CipherIS used Ask the Experts™
on
I am writing code and implementing the code sample in the below url from Silicon Expert.

https://www.siliconexpert.com/apidocs/content/list-part-search

The sample code produced error:  "The request was aborted: Could not create SSL/TLS secure channel."

Searching I found that the below code should be implemented.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AllwaysGoodCertificate);

Open in new window

Below is the full example.  
String username = "MyUserName";
String password = "MyPassword";

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AllwaysGoodCertificate);

string url = "https://app.siliconexpert.com/SearchService/search/authenticateUser?login=" + username + "&apiKey=" + password;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultCredentials;
CookieContainer cookieContainer = request.CookieContainer = new CookieContainer();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
String searchUrl = "https://app.siliconexpert.com/SearchService/search/xref?parts=[{\"partNumber\":\"bav99\"}]&crossType=B";
request = (HttpWebRequest)WebRequest.Create(searchUrl);
request.CookieContainer = cookieContainer;
response = (HttpWebResponse)request.GetResponse();
String results = new System.IO.StreamReader(response.GetResponseStream(), ASCIIEncoding.ASCII).ReadToEnd();
Console.WriteLine(results);
Console.ReadLine();

Open in new window

I am receiving

<?xml version="1.0" encoding="UTF-8"?><ServiceResult><Status><Code>1</Code><Message>Invalid User Name Or Password</Message><Success>false</Success></Status></ServiceResult>

Yet, when I log into the site and perform a search there is no issue.

Anyone see anything that I'm missing?  Want to check to see if it is the code or the site.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Hi CipherIS,

Which version of .Net Framework your app is using?

Regards,
Chinmay.

Author

Commented:
Framework I'm using is 4.5.  

I found the issue.  Apparently, another login is needed for the API.  Waiting for those credentials and then how it goes.
Kyle AbrahamsSenior .Net Developer

Commented:
I would also remove  SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls as they are both already hacked.  If you end up transmitting with either of those protocols the information is public.
Commented:
The website requires different credentials to use the API.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial