コード例 #1
0
    public static void SendPacket(int toClient, ServerPacket type, Dictionary <string, object> packetData, bool udp = false, bool useEncrypt = true)
    {
        string        clientHash = Server.clients[toClient].loginHash;
        RSAParameters clientKey  = Server.clients[toClient].remoteKey;

        using (Packet packet = new Packet())
        {
            packet.Write(useEncrypt);

            // SEND: Packet subtype and quantity of data within packet.
            packet.Write(type.ToString());
            packet.Write(packetData.Count());

            // SEND: Packet data.
            foreach (KeyValuePair <string, object> pair in packetData)
            {
                string packet_line = $"{pair.Key}|{ParseSendObject(pair.Value)}|{pair.Value.GetType()}";
                packet.Write(!useEncrypt ? packet_line : Cryptograph.Encrypt(clientKey, Cryptograph.SHA256Encrypt(packet_line, clientHash)));
            }

            if (udp)
            {
                SendUDPData(toClient, packet);
            }
            else
            {
                SendTCPData(toClient, packet);
            }
        }
    }
コード例 #2
0
        protected void Send(Packet outPacket)
        {
            short  packetOPCODE = outPacket.OperationCode;
            string packetName   = Enum.GetName(typeof(TSendOP), packetOPCODE);

            byte[] packetByteArray = outPacket.Array;
            string currentTime     = DateTime.Now.ToString("HH:mm:ss");

            outPacket.SafeFlip();
            Socket.Send(Cryptograph.Encrypt(outPacket.GetContent()));

            if (Enum.IsDefined(typeof(TSendOP), outPacket.OperationCode))
            {
                switch (Packet.LogLevel)
                {
                case LogLevel.Name:
                    Log.Inform("[{0}][ServerHandler]: \n Sent [{1}] packet.", currentTime, packetName);
                    break;

                case LogLevel.Full:
                    Log.Hex("Sent {0} packet: ", outPacket.GetContent(), Enum.GetName(typeof(TSendOP), outPacket.OperationCode));
                    break;

                case LogLevel.None:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            else
            {
                Log.Hex("Sent unknown ({0:X2}) packet: ", packetByteArray, packetOPCODE);
            }
        }
コード例 #3
0
    /// <summary> Send a packet to endpoint </summary>
    /// <param name="action">Packet ID</param>
    /// <param name="packetData">Packet content</param>
    /// <param name="udp">UDP Enabled</param>
    /// <param name="useEncrypt">Use RSA/SHA256 encryption</param>
    public static void SendPacket(ClientPacket action, Dictionary <string, object> packetData, bool udp = false, bool useEncrypt = true)
    {
        string clientHash = Client.instance.loginHash;

        System.Security.Cryptography.RSAParameters clientKey = Client.instance.serverKey;

        using (Packet packet = new Packet((int)ClientPackets.welcomeReceived))
        {
            // SEND: Encryption enabled / packet ID.
            packet.Write(useEncrypt);
            packet.Write(action.ToString());

            // SEND: Data count & data converted in string format.
            packet.Write(packetData.Count());
            foreach (KeyValuePair <string, object> pair in packetData)
            {
                string packet_line = string.Join("|", new string[3] {
                    pair.Key, ParseSendObject(pair.Value), pair.Value.GetType().ToString()
                });
                Debug.Log(packet_line);
                packet.Write(!useEncrypt ? packet_line : Cryptograph.Encrypt(clientKey, Cryptograph.SHA256Encrypt(packet_line, clientHash)));
            }

            // SEND: With UDP style traffic if boolean "udp" is true, otherwise TCP.
            if (udp)
            {
                SendUDPData(packet);
            }
            else
            {
                SendTCPData(packet);
            }
        }
    }
コード例 #4
0
 public void RightEncrypt()
 {
     if (Cryptograph.Encrypt(outpword, "скорпион") == inpword)
     {
         if (Cryptograph.Encrypt(outptxt, "скорпион") == inptxt)
         {
             Assert.Pass();
         }
     }
 }
コード例 #5
0
        private void LoginMethod(PasswordBox pb)
        {
            dbContext = new CinemaContext();
            Password  = pb.Password;
            var password = Cryptograph.Encrypt(Password);
            var user     = dbContext.Users.FirstOrDefault(i => i.Login.ToLower() == this.UserName.ToLower() && i.Password == password);

            if (user == null)
            {
                IncorrectPasswordVisibility = Visibility.Visible;
                PropertyChangedVisibility();
            }
            else
            {
                pb.Password = null;
                CleanAll();
                ParentMainWindowViewModel.Login(user);
            }
        }
コード例 #6
0
            public void EncryptMessage(string encryptedMessage, int key, string decryptedMessage)
            {
                var result = Cryptograph.Encrypt(decryptedMessage, key);

                Assert.AreEqual(encryptedMessage, result);
            }
コード例 #7
0
 private void bencrypt_Click(object sender, RoutedEventArgs e)
 {
     toutput.Text = Cryptograph.Encrypt(tinput.Text, tkey.Text);
 }
コード例 #8
0
        public void Send(Packet outPacket)
        {
            lock (this)
            {
                if (IsAlive)
                {
                    short  packetOPCODE    = outPacket.OperationCode;
                    string packetName      = Enum.GetName(typeof(TSendOP), packetOPCODE);
                    byte[] packetByteArray = outPacket.Array;
                    string currentTime     = DateTime.Now.ToString("HH:mm:ss");

                    // add new packet event to log que
                    LogEventQue.LogEvent newLogEvent = new LogEventQue.LogEvent
                    {
                        EventTime = currentTime,
                        EventName = packetName,
                        EventData = packetByteArray
                    };

                    outPacket.SafeFlip();
                    Socket.Send(Cryptograph.Encrypt(outPacket.GetContent()));

                    if (Enum.IsDefined(typeof(TSendOP), outPacket.OperationCode))
                    {
                        if (LogEventQue.NormalEventsLog.Count > 499)
                        {
                            LogEventQue.LogEvent lastLogEvent = LogEventQue.NormalEventsLog.FirstOrDefault();

                            LogEventQue.NormalEventsLog.Remove(lastLogEvent);
                            LogEventQue.NormalEventsLog.Add(newLogEvent);
                        }

                        LogEventQue.NormalEventsLog.Add(newLogEvent);

                        switch (Packet.LogLevel)
                        {
                        case LogLevel.Name:
                            Log.Inform("[{0}][ClientHandler]: \n Sent [{1}] packet to [{2}].", newLogEvent.EventTime, newLogEvent.EventName, Title);
                            break;

                        case LogLevel.Full:
                            Log.Hex("Sent {0} packet to {1}: ", outPacket.GetContent(), Enum.GetName(typeof(TSendOP), outPacket.OperationCode), Title);
                            break;

                        case LogLevel.None:
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                    else
                    {
                        Log.SkipLine();
                        Log.Hex("Sent unknown (0x{0:X2}) packet to {1}: ", outPacket.Array, outPacket.OperationCode, Title);
                        Log.SkipLine();

                        LogEventQue.AnomalousEventsLog.Add(newLogEvent);
                    }
                }
                else
                {
                    //Log.Warn("Tried to send {0} packet to dead client.", Enum.GetName(typeof(TSendOP), Packet.OperationCode));
                }
            }
        }