Пример #1
0
        async void sendMessage(string message)
        {
            byte[] buf;
            if (status != clientStatus.ENCRYPTED)
            {
                return;
            }
            string cipher = string.Empty;

            for (int i = 0; i < message.Length; i += 8)
            {
                DESCrypt crypt = new DESCrypt();
                cipher += crypt.Encrypt(message.Substring(i, message.Length - i >= 8 ? 8 : message.Length - i), key);
            }
            buf = System.Text.Encoding.ASCII.GetBytes(cipher);
            if (stream.CanWrite)
            {
                await stream.WriteAsync(buf, 0, buf.Length);

                // System.Console.WriteLine("Phy Send: {0}",cipher);
            }
        }
Пример #2
0
        async void sendMessageToClient(string message, clientInfo info)
        {
            byte[]    buf;
            TcpClient client = info.Client;

            if (!client.Connected)
            {
                return;
            }
            NetworkStream stream = client.GetStream();
            string        cipher = string.Empty;

            for (int i = 0; i < message.Length; i += 8)
            {
                DESCrypt crypt = new DESCrypt();
                cipher += crypt.Encrypt(message.Substring(i, message.Length - i >= 8 ? 8 : message.Length - i), info.Key);
            }
            buf = System.Text.Encoding.ASCII.GetBytes(cipher);
            if (stream.CanWrite)
            {
                await stream.WriteAsync(buf, 0, buf.Length);
            }
            // stream.Close();
        }