//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);
        }
        //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);
        }
        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);
        }
        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);
        }
        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);
        }
        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");
            }
        }