private void ListenerThreadEncrypted(object state)
        {
            ListenerThreadState listenerThreadState = (ListenerThreadState)state;
            IPEndPoint          endPoint            = listenerThreadState.EndPoint;

            //string key = "dnnnnnnnnnnnnnn1dnnnnnnnnnnnnnn1";//klucz ustalony przez DH jako string lub byte []
            try
            {
                while (isListening)
                {
                    Thread.Sleep(10);

                    if (udpListener.Available > 0)
                    {
                        byte[] b = this.udpListener.Receive(ref endPoint);

                        var    decrypted = new cscprotocol.CscAes(callingService.DHKey).DecryptBytes(b, 800);
                        byte[] decoded   = listenerThreadState.Codec.Decode(decrypted, 0, decrypted.Length);//!! odbieranie dzwieku

                        //Trace.WriteLine("Received: "+Encoding.ASCII.GetString(decrypted));

                        waveProvider.AddSamples(decoded, 0, decoded.Length);
                    }
                }
                isListening = false;
                udpListener.Close();
            }
            catch (Exception)
            {
                isListening = false;
                HideIncomingCallWindow();
                //Disconnected
            }
        }
Exemplo n.º 2
0
        //n zunifikowana zmiana stanu usera !!!!
        public byte[] CreateUnifiedUserDataMessageEncrypted(CscUserMainData userMainData, byte[] key)//CreateFriendUserDataMessage
        {
            var friendsAsBytes          = CscProtocol.Serialize(userMainData);
            var friendsAsBytesEncrypted = new CscAes(key).EncryptBytesToBytes(friendsAsBytes);
            var message = new byte[3 + friendsAsBytesEncrypted.Length];

            message[0] = 4;
            BitConverter.GetBytes((UInt16)friendsAsBytesEncrypted.Length).CopyTo(message, 1);
            friendsAsBytesEncrypted.CopyTo(message, 3);
            return(message);
        }
Exemplo n.º 3
0
        //public CscUserData ReadUserData(byte[] message)
        //{
        //    var result = DeserializeWithLengthInfo(message) as CscUserData;

        //    if (result == null)
        //        throw new NullReferenceException();
        //    else
        //        return result;
        //}

        //user pasujacy do zapytania wyszukiwania userow
        public byte[] CreateSearchUserDataResponseEncrypted(CscUserMainData searchUserData, byte[] key)
        {
            var searchUserAsBytes          = CscProtocol.Serialize(searchUserData);
            var searchUserAsBytesEncrypted = new CscAes(key).EncryptBytesToBytes(searchUserAsBytes);
            var message = new byte[3 + searchUserAsBytesEncrypted.Length];

            message[0] = 3;
            BitConverter.GetBytes((UInt16)searchUserAsBytesEncrypted.Length).CopyTo(message, 1);
            searchUserAsBytesEncrypted.CopyTo(message, 3);
            return(message);
        }
Exemplo n.º 4
0
        public byte[] CreateRemoveUserFromFriendsListRequestEncrypted(CscChangeFriendData userData, byte[] key)
        {
            var    mainMessagePlain  = Serialize(userData);
            var    mainMessage       = new CscAes(key).EncryptBytesToBytes(mainMessagePlain);
            UInt16 mainMessageLength = (UInt16)mainMessage.Length;

            byte[] lenghtBytes = BitConverter.GetBytes(mainMessageLength);
            byte[] fullData    = new byte[1 + lenghtBytes.Length + mainMessageLength];
            fullData[0] = 5;
            lenghtBytes.CopyTo(fullData, 1);
            mainMessage.CopyTo(fullData, lenghtBytes.Length + 1);
            return(fullData);
        }
Exemplo n.º 5
0
 public static void AES_example()
 {
     try
     {
         string key           = "dnnnnnnnnnnnnnn1dnnnnnnnnnnnnnn1";//klucz ustalony przez DH jako string lub byte []
         CscAes aes_en        = new CscAes(key);
         var    ECB_encrypted = aes_en.EncryptStringToBytes("Taka tam wiadomosc odszyfrowana.", CipherMode.ECB);
         var    ECB_decrypted = aes_en.DecryptStringFromBytes(ECB_encrypted, CipherMode.ECB);
         Console.WriteLine(ECB_decrypted);
     }
     catch (Exception e)
     { Console.WriteLine(e.Message); }
 }
Exemplo n.º 6
0
        public byte[] CreateSearchUserRequestEncrypted(string message, byte[] key)
        {
            var    mainMessage   = new CscAes(key).EncryptStringToBytes(message);
            UInt16 messageLength = (UInt16)mainMessage.Length;
            var    lenghtBytes   = BitConverter.GetBytes(messageLength);

            byte[] result = new byte[mainMessage.Length + lenghtBytes.Length + 1];
            result[0] = 8;

            lenghtBytes.CopyTo(result, 1);
            mainMessage.CopyTo(result, lenghtBytes.Length + 1);

            return(result);
        }
Exemplo n.º 7
0
        public byte[] CreateRegistrationMessageEncrypted(CscUserData userData, byte[] key)
        {
            var    mainMessagePlain  = Serialize(userData);
            var    mainMessage       = new CscAes(key).EncryptBytesToBytes(mainMessagePlain);
            UInt16 mainMessageLength = (UInt16)mainMessage.Length;


            byte[] lenghtBytes = BitConverter.GetBytes(mainMessageLength);
            byte[] fullData    = new byte[1 + lenghtBytes.Length + mainMessageLength];
            fullData[0] = 2;
            lenghtBytes.CopyTo(fullData, 1);
            mainMessage.CopyTo(fullData, lenghtBytes.Length + 1);
            return(fullData);
        }
        void WaveIn_DataAvailableEncrypted(object sender, WaveInEventArgs e)
        {
            //$$$ szyfrowanie tutaj
            if (micOn)
            {
                byte[] encoded = codec.Encode(e.Buffer, 0, e.BytesRecorded);//!!! wysylanie dzwieku
                //string key = "dnnnnnnnnnnnnnn1dnnnnnnnnnnnnnn1";//klucz ustalony przez DH jako string lub byte []

                var encrypted = new cscprotocol.CscAes(callingService.DHKey).EncryptBytes(encoded);

                udpSender.Send(encrypted, encrypted.Length);

                //długość próbki dźwięku po zakodowaniu wynosi 800!!!
                //przy odebraniu bajtów pierwsze 800 jest od dźwięku, reszta to śmieci z wypełnienia do pełnego bloku
                //Trace.WriteLine(encrypted.Length);
                //Trace.WriteLine(encoded.Length);
            }
        }
Exemplo n.º 9
0
        public byte[] CreateConfirmMessageEncrypted(string message, byte[] key)
        {
            if (!string.IsNullOrEmpty(message))
            {
                var    mainMessage   = new CscAes(key).EncryptStringToBytes(message);
                UInt16 messageLength = (UInt16)mainMessage.Length;
                var    lenghtBytes   = BitConverter.GetBytes(messageLength);

                byte[] result = new byte[mainMessage.Length + lenghtBytes.Length + 1];
                result[0] = 12;

                lenghtBytes.CopyTo(result, 1);
                mainMessage.CopyTo(result, lenghtBytes.Length + 1);
                return(result);
            }
            else
            {
                throw new ArgumentNullException("Message cannot be null");
            }
        }