Using System.Net.WebClient with HTTPS certificate

后端 未结 4 1251
轻奢々
轻奢々 2021-02-05 20:11

In my C# Windows client, I have a POST submission to \"the mothership\". I want the data in the submits to be secured, of course, so I paid for HostGator to issue me an SSL cert

相关标签:
4条回答
  • 2021-02-05 20:21

    Sounds like you are doing it backwards. You should have the SLL Certificate installed on the web host/server. Then you create a web request to web server and requires the HTTPS protocol.

    0 讨论(0)
  • 2021-02-05 20:28

    Client certificates will work only if the private key is available. This is not generally the case when using .cer files since the X.509 certificate does not include the private key.

    The only safe way to ensure the private key is available is to load the certificate from a PKCS#12 file where both the certificate(s) and the private key are available (i.e. both were exported into the .pfx file).

    Notes:

    • I said generally because Windows/CryptoAPI sometimes does some magic (when used with X509Certificate) and automatically associate a certificate with a private key from the certificate.key stores.

    • I said safe because that will work on Mono too, not just MS .NET.

    0 讨论(0)
  • 2021-02-05 20:28

    Just connect to your server with RDP

    Open IE and go to Internet Options

    Navigate to Advanced Tab and Enable both Use SSL 2.0 and SSL 3.0

    Now your server requests will be authenticated

    0 讨论(0)
  • 2021-02-05 20:32

    If you're not using client certificates and you can access your server using https:// then your code should look like:

    private static WebClient client = new WebClient();
    private static NameValueCollection nvc= new NameValueCollection();
    
    nvc.Add(POST_ACTION, ACTION_CODE_LOGIN);
    nvc.Add(POST_EMAIL, email);
    nvc.Add(POST_PASSWORD, password);
    
    sResponse = System.Text.Encoding.ASCII.GetString(client.UploadValues(BASE_URL + ACTION_PAGE, nvc));
    

    As long as your BASE_URL uses https:// then all the data (to and from the server) will be encrypted.

    IOW using SSL/TLS from a client to a server does not require the client to do anything special (with the certificate), besides using https:// as the scheme, since the operating system provides everything (e.g. trusted roots) you need to secure the data transmission.

    0 讨论(0)
提交回复
热议问题