Пример #1
0
        public void SendMessage(string msg)
        {
            if (key == null)
            {
                return;
            }
            string enMsg = CryptoClass.TDESencodeString(msg, key);

            byte[] endMsg = Encoding.ASCII.GetBytes(enMsg);
            try
            {
                ns.Write(endMsg, 0, endMsg.Length);
            }
            catch (Exception ex)
            {
            }
        }
Пример #2
0
        private void GetAuth()
        {
            //kanalas per kuri bus komunikuojama
            byte[] buffer = new byte[1024];
            //nuskaitom info is rysio
            ns.Read(buffer, 0, buffer.Length);

            int usernameLength = BitConverter.ToInt32(buffer, 0);

            username = Encoding.ASCII.GetString(buffer, sizeof(int), usernameLength);

            int publicKeyLength = BitConverter.ToInt32(buffer, sizeof(int) + usernameLength);

            string publicKey = Encoding.ASCII.GetString(buffer, sizeof(int) * 2 + usernameLength, publicKeyLength);


            DialogResult result = MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                // priimti clienta
                key = CryptoClass.RandomString(20);

                string encryptedKey = CryptoClass.RSAencodeString(key, publicKey);

                byte[] encryptedKeyBytes = Encoding.ASCII.GetBytes(encryptedKey);
                ns.Write(encryptedKeyBytes, 0, encryptedKeyBytes.Length);
                // MessageBox.Show("s: "+ key);
            }
            else
            {
                dListeners(this);
                ns.Close();
                client.Close();
            }
        }