123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System.Collections.Generic;
- using System.IO;
- using System.Security.Authentication;
- using System.Security.Cryptography.X509Certificates;
- using System.Net.Security;
- namespace IFramework.Net.WebSocket
- {
- public class SslHelper
- {
- private string certificate = string.Empty;
- X509Certificate serverCertificate = null;
- private int bufSize = 4096;
- public SslHelper(string certificateFile)
- {
- serverCertificate = X509Certificate.CreateFromCertFile(certificateFile);
- }
- public byte[] DeCryptFromServer(byte[] buffer, int offset, int size)
- {
- using (SslStream sslStream = new SslStream(new MemoryStream(buffer, offset, size), false))
- {
- sslStream.AuthenticateAsServer(serverCertificate, false, SslProtocols.Tls, true);
- List<byte> msg = new List<byte>(bufSize);
- int b = -1;
- {
- b = sslStream.ReadByte();
- if (b != -1) msg.Add((byte)b);
- } while (b != -1) ;
-
- return msg.ToArray();
- }
- }
- public byte[] EnCryptFromServer()
- {
- return null;
- }
- public byte[] DeCryptFromClient()
- {
- return null;
- }
- public byte[] EnCryptFromClient()
- {
- return null;
- }
- }
- }
|