This article introduces the open-source. net Communication Framework NetworkComms framework-six x509 Certificate communication, networkcommsx509

Source: Internet
Author: User
Tags pfx file

This article introduces the open-source. net Communication Framework NetworkComms framework-six x509 Certificate communication, networkcommsx509

Http://www.cnblogs.com/csdev

Networkcomms is a C # TCP/UDP communication framework written by the British. It was previously charged by the British. Currently, the author has open-source License: Apache License v2.

Open Source Address: https://github.com/MarcFletcher/NetworkComms.Net

First of all, I am not particularly familiar with the certificate, but I just reorganized the Demo of NetworkComms itself. If not, criticize and correct it.

 

First

Server:

(1) generate a certificate:

   public void CreateCert()        {            if (!File.Exists("testCertificate.pfx"))            {                CertificateDetails details = new CertificateDetails("CN=wwww", DateTime.Now, DateTime.Now.AddYears(1));                SSLTools.CreateSelfSignedCertificatePFX(details, "testCertificate.pfx");            }                      X509Certificate cert = new X509Certificate2("testCertificate.pfx");            sslOptions = new SSLOptions(cert, true);        }

In the above Code, the certificate is assigned to sslOptions as a parameter.

SslOptions will be assigned to the listener. The Code is as follows:

      ConnectionListenerBase listener = new TCPConnectionListener(customOptions, ApplicationLayerProtocolStatus.Enabled,sslOptions);       Connection.StartListening(listener, thePoint, true);

 

The running server generates

TestCertificate. pfx file. We need to copy this file to the client.

Client code:

X509Certificate cert = new X509Certificate2 ("testCertificate. pfx "); SSLOptions sslOptions = new SSLOptions (cert, true); connInfo = new ConnectionInfo (txtIP. text, int. parse (txtPort. text); newTcpConnection = TCPConnection. getConnection (connInfo, customOptions, sslOptions); button1.Enabled = false; button1.Text = "connection successful ";

 

In this way, clients without certificates cannot establish connections with the server.

 

Source code: http://pan.baidu.com/s/1dEJEdNz

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.