static void Main(string[] args)
        {
            var encrypter = new Encrypter(KEY);

            Console.WriteLine("Encrypt then decrypt same data (TODO: figure out what the value wrapping is about)");
            var encrypted = encrypter.Encrypt("s:6:\"121212\";");

            Console.WriteLine("Encrypted: {0}", encrypted);
            var decrypted = encrypter.Decrypt(encrypted);

            Console.WriteLine("Decrypted: {0}", decrypted);

            Console.WriteLine("Decrypt an earlier instance of this encrypter's output");
            decrypted = encrypter.Decrypt("eyJpdiI6InlWb3k3bHFVU2d2eTBFRWFGQWRmVVE9PSIsInZhbHVlIjoieThYZnFpakFobEg1cnU2NDZmcmVPdz09IiwibWFjIjoiOGUyMjRhNzM2ZmVmYjFmYjVjY2ZlMjU4ZDk3ZWJiNTIwMTcwNzM4NmUyOTFkYTJiNGNiNjNhZTgwMjFlZTY2MiJ9");
            Console.WriteLine("Decrypted: {0}", decrypted);

            Console.WriteLine("Decrypt an instance of the Laravel encrypter's output");
            try
            {
                decrypted = encrypter.Decrypt(DB_FIELD);
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("An original will not convert because the MAC cannot match.");
            }

            Console.ReadLine();
        }
Example #2
0
 protected string GetUserNameFromCookie(HttpCookie cookie)
 {
     try
     {
         return(encrypter.Decrypt(cookie.Value));
     }
     catch (Exception)
     {
         return(null);
     }
 }
Example #3
0
        public void Connect()
        {
            Encrypter encrypter = new Encrypter("64bit");

            String keyword = encrypter.Decrypt("QnV0IHlvdSBkb24ndCByZWFsbHkgbWVhbiBpdA==");

            // Check if crypter is changed
            Assert.AreEqual(true, encrypter.SetCrypter("AES"));

            this.connection = encrypter.Decrypt
                ("Sf+ulELX4tNuvsQtUG2EZWPJDPhm8obnrSyEm7F5mtg/eziYSjoIZndeCHk8iZOhvAuMNJBxiiatrRHTt2LVFv/vJNoo8yCHkOO7TwUWv3+l8+Wpis4TSsEvc8zHgEPIucH/OQ2tyYlMboyoFH26dZLZ2Y+Kevfu79VfqLBcKGE=", keyword);
        }
 /*public ISessionFactory Session
 {
     get
     {
         session = fluentCfg.BuildSessionFactory();
         return session;
     }
 }*/
 public DatabaseConfiguration()
 {
     Encrypter encrypter = new Encrypter("64bit");
     string keyword = encrypter.Decrypt("QnV0IHlvdSBkb24ndCByZWFsbHkgbWVhbiBpdA==");
     encrypter.SetCrypter("AES");
     this.connectionString = encrypter.Decrypt("Sf+ulELX4tNuvsQtUG2EZWPJDPhm8obnrSyEm7F5mtg/eziYSjoIZndeCHk8iZOhvAuMNJBxiiatrRHTt2LVFv/vJNoo8yCHkOO7TwUWv3+l8+Wpis4TSsEvc8zHgEPIucH/OQ2tyYlMboyoFH26dZLZ2Y+Kevfu79VfqLBcKGE=", keyword);
     fluentCfg = Fluently.Configure().Database(PostgreSQLConfiguration.Standard.ConnectionString(this.connectionString)).Mappings(m =>
     {
         m.HbmMappings.AddFromAssemblyOf<Users>();
         m.HbmMappings.AddFromAssemblyOf<Contacts>();
     });
     var config = fluentCfg.BuildSessionFactory();
 }
Example #5
0
        public void Given_a_null_value_then_when_encrypted_or_decrypted_no_exception_is_thrown_and_null_is_returned()
        {
            var sut = new Encrypter(TestData.TestConfiguration);

            var encrypted = sut.Encrypt(null);

            Assert.DoesNotThrow(() => sut.Encrypt(null));
            Assert.IsNull(encrypted);

            var decrypted = sut.Decrypt(encrypted);

            Assert.DoesNotThrow(() => sut.Decrypt(encrypted));
            Assert.IsNull(decrypted);
        }
        public void Users_can_be_persisted_and_retrieved()
        {
            //Arrange
            var sutProvider  = new DataProvider <User>(_config, User.ToDomainConverter);
            var columns      = sutProvider.LoadAllColumns();
            var sutPersister = new UserPersister(columns, _config);

            //Act
            ErrorMessage error;
            var          persistResult = sutPersister.TryPersist(ref TestData.Users.NewMeJulie, out error);

            //Assert
            Assert.IsTrue(persistResult);
            Assert.IsNull(error);

            //The new row id is assigned to ref of the object
            Assert.IsNotNull(TestData.Users.MeJulie.UserId);
            Assert.IsInstanceOf <int>(TestData.Users.MeJulie.UserId);

            var readResult = sutProvider.LoadAll().First();

            Assert.AreEqual(TestData.Users.MeJulie.Email, readResult.Email);
            Assert.AreEqual(TestData.Users.MeJulie.Username, readResult.Username);
            Assert.AreEqual(TestData.Users.MeJulie.FirstName, readResult.FirstName);
            Assert.AreEqual(TestData.Users.MeJulie.LastName, readResult.LastName);

            Assert.AreNotEqual(TestData.Users.MeJulie.Password, readResult.Password);
            Assert.AreEqual(_encrypter.Encrypt(TestData.Users.MeJulie.Password), readResult.Password);
            Assert.AreEqual(TestData.Users.MeJulie.Password, _encrypter.Decrypt(readResult.Password));
        }
Example #7
0
    public static void Main()
    {
        string newText = Encrypter.Encrypt("Hola");

        Console.WriteLine(newText);
        Console.WriteLine(Encrypter.Decrypt(newText));
    }
        public void TestEncryptionAgainstOne()
        {
            String password         = Encrypter.Encrypt("password", "raspberryberet");
            String originalpassword = Encrypter.Decrypt(password, "raspberryberet");

            Assert.AreEqual("password", originalpassword);
        }
Example #9
0
    public override object ReadJson(JsonReader reader, Type type, object existingValue, JsonSerializer serializer)
    {
        var value     = (string)reader.Value;
        var decrypted = encrypter.Decrypt(value);

        return(innerConverter.Deserialize(type, serializer, decrypted, existingValue));
    }
    public override object?ReadJson(JsonReader reader, Type type, object?existingValue, JsonSerializer serializer)
    {
        var value     = (string)reader.Value !;
        var decrypted = encrypter.Decrypt(value);

        return(serializer.Deserialize(type, decrypted));
    }
        public async Task <IActionResult> OrderTjeck(OrdreViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (_context.ZipCodes.FirstOrDefault(i => i.ZipCode == model.Zipcode) == null)

            {
                ModelState.AddModelError("ZipCode", "Postnummer findes ikke");

                return(View(model));
            }

            var ordre = _context.Ordre.FirstOrDefault(i => i.Orderid == Encrypter.Decrypt(model.Token));

            ordre.KortholderNavn = model.KortholderNavn;

            ordre.Address = model.Address;

            ordre.Zipcode = model.Zipcode;

            ordre.Email = model.Email;

            _context.Ordre.Update(ordre);

            _context.SaveChanges();

            return(RedirectToAction("Details", new { id = ordre.Orderid }));
        }
Example #12
0
        private void DisplayAccounts()
        {
            ClearUI();

            // Insert new data into UI
            int index = 0;

            foreach (KeyValuePair <string, string[]> data in accountData)
            {
                titleLabels[index].Text   = Encrypter.Decrypt(data.Key, encryptionKey);
                accountLabels[index].Text = Encrypter.Decrypt(data.Value[1], encryptionKey);

                accountPanels[index].Visible       = true;
                titleLabels[index].Visible         = true;
                accountLabels[index].Visible       = true;
                copyURLButtons[index].Visible      = true;
                copyAccountButtons[index].Visible  = true;
                copyPasswordButtons[index].Visible = true;
                editButtons[index].Visible         = true;
                deleteButtons[index].Visible       = true;

                if (index + 1 >= accountLimit)
                {
                    AddAccountButton.Enabled = false;
                    break;
                }

                index++;
            }
        }
Example #13
0
 void Decrypt()
 {
     if (MessageText != null && KeyText != null)
     {
         MessageText = encrypter.Decrypt(MessageText, KeyText);
     }
 }
Example #14
0
        public void EncryptDecrypt_LongString_ShouldReturnSameString(string expected)
        {
            string encrypted = Encrypter.Encrypt(expected, encryptionKey);
            string actual    = Encrypter.Decrypt(encrypted, encryptionKey);

            Assert.Equal(expected, actual);
        }
Example #15
0
        private void OnRead(IAsyncResult ar)
        {
            try
            {
                int count = this.stream.EndRead(ar);
                this.totalBuffer += Encrypter.Decrypt(this.buffer.SubArray(0, count), "password123");

                string eof = $"<{Tag.EOF.ToString()}>";
                while (this.totalBuffer.Contains(eof))
                {
                    string packet = this.totalBuffer.Substring(0, this.totalBuffer.IndexOf(eof) + eof.Length);
                    this.totalBuffer = this.totalBuffer.Substring(packet.IndexOf(eof) + eof.Length);

                    this.HandlePacket(packet);
                }
                this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(this.OnRead), null);
            }
            catch (IOException)
            {
                this.stream.Close();
                this.client.Close();
                this.server.Clients.Remove(this);
                Console.WriteLine("Client disconnected");
            }
        }
Example #16
0
        public void EncryptDecryptTest()
        {
            var text1 = "text-to-encrypt";
            var text2 = "another-text-to-encrypt";

            var encrypter = new Encrypter();
            var salt1     = new byte[24] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
            };
            var salt2 = new byte[24] {
                1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2
            };

            var encr1 = encrypter.Encrypt(text1, salt1);
            var encr2 = encrypter.Encrypt(text1, salt1);

            Assert.AreNotEqual(encr1, encr2);

            var decr1 = encrypter.Decrypt(encr1, salt1);
            var decr2 = encrypter.Decrypt(encr2, salt1);

            Assert.AreEqual(decr1, decr2);

            encr1 = encrypter.Encrypt(text1, salt1);
            encr2 = encrypter.Encrypt(text2, salt1);
            Assert.AreNotEqual(encr1, encr2);

            decr1 = encrypter.Decrypt(encr1, salt1);
            decr2 = encrypter.Decrypt(encr2, salt1);
            Assert.AreNotEqual(decr1, decr2);

            encr1 = encrypter.Encrypt(text1, salt1);
            encr2 = encrypter.Encrypt(text1, salt2);
            Assert.AreNotEqual(encr1, encr2);

            decr1 = encrypter.Decrypt(encr1, salt1);
            decr2 = encrypter.Decrypt(encr2, salt2);
            Assert.AreEqual(decr1, decr2);

            encr1 = encrypter.Encrypt(text1, salt1);
            encr2 = encrypter.Encrypt(text2, salt2);
            Assert.AreNotEqual(encr1, encr2);

            decr1 = encrypter.Decrypt(encr1, salt1);
            decr2 = encrypter.Decrypt(encr2, salt2);
            Assert.AreNotEqual(decr1, decr2);

            encr1 = encrypter.Encrypt(text1, salt1);
            Assert.Throws <CryptographicException>(() => encrypter.Decrypt(encr1, salt2));
        }
Example #17
0
        public XConnection()
        {
            Encrypter encrypter = new Encrypter("64bit");

            String keyword = encrypter.Decrypt("QnV0IHlvdSBkb24ndCByZWFsbHkgbWVhbiBpdA==");

            if (encrypter.SetCrypter("AES"))
            {
                String connection = encrypter.Decrypt
                    ("Sf+ulELX4tNuvsQtUG2EZWPJDPhm8obnrSyEm7F5mtg/eziYSjoIZndeCHk8iZOhvAuMNJBxiiatrRHTt2LVFv/vJNoo8yCHkOO7TwUWv3+l8+Wpis4TSsEvc8zHgEPIucH/OQ2tyYlMboyoFH26dZLZ2Y+Kevfu79VfqLBcKGE=", keyword);

                _Connection = new NpgsqlConnection(connection);
            }
            else
            {
                throw new XConnectionException();
            }
        }
    public static void Main()
    {
        Encrypter eTest     = new Encrypter();
        string    text      = "hola";
        string    encrypted = eTest.Encrypt(text);

        Console.WriteLine(encrypted);
        Console.WriteLine(eTest.Decrypt(encrypted));
    }
Example #19
0
    static void Main()
    {
        string sentence          = "Hello";
        string sentenceEncrypted = Encrypter.Encrypt(sentence);

        Console.WriteLine(sentenceEncrypted);

        Console.WriteLine(Encrypter.Decrypt(sentenceEncrypted));
    }
Example #20
0
    public static void Main()
    {
        string newText = Encrypter.Encrypt("Hola");

        Console.WriteLine("Hola becomes {0}", newText);

        Console.WriteLine("And it decrypts to {0}",
                          Encrypter.Decrypt(newText));
    }
    public static void Main()
    {
        Encrypter e          = new Encrypter();
        string    nuevoTexto = e.Encrypt("Hola");

        Console.WriteLine(nuevoTexto);
        nuevoTexto = e.Decrypt(nuevoTexto);
        Console.WriteLine(nuevoTexto);
    }
Example #22
0
    static void Main()
    {
        string newText = Encrypter.Encrypt("Hola");

        Console.WriteLine(newText);
        newText = Encrypter.Decrypt(newText);
        Console.WriteLine(newText);
        Console.ReadLine();
    }
 private void button_Click(object sender, RoutedEventArgs e)
 {
     System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(@"c:\Temp");
     //   _encrypter = new Encrypter(directory);
     _encrypter = new Encrypter(new System.IO.FileInfo("c:\\Temp\\privateKey.xml"), directory);
     //_encrypter.GenerateKeys();
     //_encrypter.Encrypt(new System.IO.FileInfo(@"c:\Temp\Sample.txt"));
     _encrypter.Decrypt(new System.IO.FileInfo(@"c:\Temp\Sample.txt.enc"));
 }
Example #24
0
    static void Main()
    {
        Encrypter e                 = new Encrypter();
        string    sentence          = "Hello";
        string    sentenceEncrypted = e.Encrypt(sentence);

        Console.WriteLine(sentenceEncrypted);

        Console.WriteLine(e.Decrypt(sentenceEncrypted));
    }
Example #25
0
        public void Given_any_string_when_encrypted_it_can_be_decrypted(string input)
        {
            var sut = new Encrypter(TestData.TestConfiguration);

            var encrypted = sut.Encrypt(input);

            Assert.AreNotEqual(encrypted, input);

            var decrypted = sut.Decrypt(encrypted);

            Assert.AreEqual(decrypted, input);
        }
Example #26
0
        public void EncryptDecrypt()
        {
            var data          = "asdf";
            var password      = "******";
            var e             = new Encrypter();
            var encryptedData = e.Encrypt(data, password);

            Assert.AreNotEqual(data, encryptedData);
            var decryptedData = e.Decrypt(encryptedData, password);

            Assert.AreEqual(data, decryptedData);
        }
Example #27
0
        //Checks if login and password are correct
        private ServerUser CheckUserInfo(TcpClient client, UserCheck userCheck)
        {
            string    passPhrase = "passPhrase";
            Encrypter encrypter  = new Encrypter();

            //Checks if needed files/directories exist
            CheckExistedFiles(Convert.ToInt32(userCheck.HouseNumber));

            Users users = JsonConvert.DeserializeObject <Users>(File.ReadAllText(@$ "data/house-{userCheck.HouseNumber}/students.json"));

            //For each user check if given credentials corespond to anyone
            foreach (var user in users.AllUsers)
            {
                if (user.Login == userCheck.Login && user.HouseNumber == userCheck.HouseNumber &&
                    encrypter.Decrypt(user.Password, passPhrase) == encrypter.Decrypt(userCheck.Password, passPhrase))
                {
                    return(user);
                }
            }

            return(null);
        }
Example #28
0
        public void Connect()
        {
            Console.WriteLine();
            TestHelper.log("Decrypting keyword");
            Encrypter encrypter = new Encrypter("64bit");
            String keyword = encrypter.Decrypt("QnV0IHlvdSBkb24ndCByZWFsbHkgbWVhbiBpdA==");
            TestHelper.done();

            TestHelper.log("Decrypting connection parameters");
            Assert.AreEqual(true, encrypter.SetCrypter("AES"));
            TestHelper.done();

            TestHelper.log("Connection decritpion");
            try
            {
                this.connection = encrypter.Decrypt
                    ("Sf+ulELX4tNuvsQtUG2EZWPJDPhm8obnrSyEm7F5mtg/eziYSjoIZndeCHk8iZOhvAuMNJBxiiatrRHTt2LVFv/vJNoo8yCHkOO7TwUWv3+l8+Wpis4TSsEvc8zHgEPIucH/OQ2tyYlMboyoFH26dZLZ2Y+Kevfu79VfqLBcKGE=", keyword);
                TestHelper.done();
            }
            catch (Exception e)
            {
                TestHelper.error(e.Message);
            }

            TestHelper.log("Connection test");
            try
            {
                NpgsqlConnection _Connection = new NpgsqlConnection(connection);
                Assert.IsNotNull(_Connection);
                TestHelper.done();
            }
            catch (Exception e)
            {
                TestHelper.error(e.Message);
            }
        }
        public static T JSONDeserialize <T>(string deserializeString, string encrytPass)
        {
            if (!string.IsNullOrEmpty(encrytPass))
            {
                deserializeString = Encrypter.Decrypt(deserializeString, encrytPass);
            }

            var jsSettings = new JsonSerializerSettings
            {
                TypeNameHandling      = TypeNameHandling.Objects,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            };

            return(JsonConvert.DeserializeObject <T>(deserializeString, jsSettings));
        }
        public async Task <IActionResult> Details(string Token, string Password)
        {
            if (Token == null)
            {
                return(NotFound());
            }

            if (string.IsNullOrEmpty(Password))
            {
                return(RedirectToAction("Details", new { id = Encrypter.Decrypt(Token), haspassworderror = true }));
            }

            var user = await _userManager.CheckPasswordAsync(_context.Users.FirstOrDefault(i => i.UserName == User.Identity.Name), Password);

            if (!user)
            {
                return(RedirectToAction("Details", new { id = Encrypter.Decrypt(Token), haspassworderror = true }));
            }

            var ordre = _context.Ordre.FirstOrDefault(i => i.Orderid == Encrypter.Decrypt(Token));

            ordre.Status = "Payment Reshived";
            _context.Ordre.Update(ordre);

            string body =
                @"<br/>Du vil modtage dine vare inde for få hverdage<br/><table><thead><tr><th>Pris</th><th>Productnavn</th></tr></thead><tbody>";

            foreach (var product in _context.OrderProduct.Where(i => i.OrderId == Encrypter.Decrypt(Token)))
            {
                var products = _context.Product.FirstOrDefault(i => i.Id == product.ProductId);
                products.NoOfItems--;
                if (products.NoOfItems < 0)
                {
                    ModelState.AddModelError("Email", "Der gik noget galt under ordren. prøv veligst igen, og vis det statid ikke virker så kontakt venligst en administator");
                    RedirectToAction("Details", new { id = Encrypter.Decrypt(Token) });
                }
                _context.Update(products);
                body = body + @"<tr><td>" + products.Price + @" DKK &nbsp</td><td>" + products.Name + @"</td></tr>";
            }
            body = body + "</tbody></table><br/><br>Total pris: " + ordre.Price + "DKK";
            _context.SaveChanges();
            EmailSender.SendEmail("Kvitering for køb", body, "Kvitering", ordre.Email);


            return(RedirectToAction("Confirmation"));
        }
 static public string GetStringEncrypted(string key, string defaultValue)
 {
     try {
         string encryptedString = Encrypter.Decrypt(PlayerPrefs.GetString(key, ""), PASS_PHRASE);
         if (encryptedString.StartsWith(ECRYPTED_PREFIX))
         {
             return(encryptedString.Remove(0, ECRYPTED_PREFIX.Length));
         }
         else
         {
             return(defaultValue);
         }
     }
     catch {
         return(defaultValue);
     }
 }
Example #32
0
        private void OnRead(IAsyncResult ar)
        {
            int count = this._stream.EndRead(ar);

            this.totalBuffer += Encrypter.Decrypt(this._buffer.SubArray(0, count), "password123");

            string eof = $"<{Tag.EOF.ToString()}>";

            while (this.totalBuffer.Contains(eof))
            {
                string packet = this.totalBuffer.Substring(0, this.totalBuffer.IndexOf(eof) + eof.Length);
                this.totalBuffer = this.totalBuffer.Substring(packet.IndexOf(eof) + eof.Length);

                this.HandlePacket(packet);
            }

            this._stream.BeginRead(this._buffer, 0, this._buffer.Length, new AsyncCallback(this.OnRead), null);
        }
        /// <summary>
        /// Checks the login of a user.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <returns>A user with the selected credentials, if one exists</returns>
        public User CheckLogin(string username, string password)
        {
            MySqlConnection dbConnection = DbConnection.GetConnection();

            using (dbConnection)
            {
                dbConnection.Open();
                var selectQuery =
                    "SELECT `users`.`uid`, `users`.password, `roles`.role_name  FROM `users`, `user_has_role`, `roles` WHERE `users`.`uid` = `user_has_role`.user_uid AND `user_has_role`.`roles_role_id` = `roles`.role_id AND users.uid = @username";

                using (MySqlCommand cmd = new MySqlCommand(selectQuery, dbConnection))
                {
                    cmd.Parameters.AddWithValue("@username", username);
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        int unameOrdinal = reader.GetOrdinal("uid");
                        int pwordOrdinal = reader.GetOrdinal("password");
                        int roleOrdinal  = reader.GetOrdinal("role_name");

                        while (reader.Read())
                        {
                            var foundusername = reader[unameOrdinal] == DBNull.Value
                                ? default(string)
                                : reader.GetString(unameOrdinal);
                            var foundpassword = reader[pwordOrdinal] == DBNull.Value
                                ? default(string)
                                : reader.GetString(pwordOrdinal);
                            var decryptedpassword = Encrypter.Decrypt(foundpassword, "raspberryberet");
                            var foundrole         = reader[roleOrdinal] == DBNull.Value
                                ? default(string)
                                : reader.GetString(roleOrdinal);
                            var foundUser = new User(foundusername, decryptedpassword, foundrole);
                            return(foundUser);
                        }
                    }
                }

                dbConnection.Close();
            }

            return(null);
        }
        public void Encrypt_Decrypt()
        {
            var key = "1234567887654321";
            Encrypter encrypter = new Encrypter(key);

            var data = @"GET http://offline.dev.wingontravel.com/Ticket/Booking/SearchFare HTTP/1.1
            Accept: text/html, application/xhtml+xml, */*
            Referer: http://offline1.dev.wingontravel.com/RightsManagement/Default.aspx
            Accept-Language: zh-CN
            User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
            Accept-Encoding: gzip, deflate
            Host: offline.dev.wingontravel.com
            Connection: Keep-Alive
            Cookie: _ga=GA1.2.1208780554.1452854271; app_pop=1; WINGON_TRACKING_CID=03635888155583694324; FIRST_DISCOUNT_ABS=1; token=00XK5jOIs7cNgdWotUrmGIpL+A0l/59NOwAu5RTN7YhTwaYcQRNFgzW9PUphv6UC7CUk2WEpdKVpZY8F4FkM24gYcMspthIUPZOa90KvzaA=";
            var dataBytes = Encoding.UTF8.GetBytes(data);
            var alfterDataBytes = encrypter.Encrypt(dataBytes);
            var decryptedDataBytes = encrypter.Decrypt(alfterDataBytes);

            Assert.AreEqual(data, Encoding.UTF8.GetString(decryptedDataBytes));
        }
        private void OnRead(IAsyncResult ar)
        {
            try
            {
                int    count = this.stream.EndRead(ar);
                string read  = Encrypter.Decrypt(this.buffer.SubArray(0, count), "password123");

                string eof = $"<{Tag.EOF.ToString()}>";
                while (read.Contains(eof))
                {
                    string packet = read.Substring(0, read.IndexOf(eof) + eof.Length);
                    read = read.Substring(packet.IndexOf(eof) + eof.Length);

                    this.HandlePacket(packet);
                }
                this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
            }
            catch (IOException)
            {
                this.Disconnect();
                Console.WriteLine("Server has shut down");
            }
        }