Beispiel #1
0
		protected void Page_Load(object sender, EventArgs e)
		{
			string returnUrl = HttpUtility.UrlDecode(Request.QueryString["ru"]);

			ITicket ticket = BuildTicket();

			if (string.IsNullOrEmpty(ticket.SignInInfo.UserID) == false)
			{
				XmlDocument xmlDoc = ticket.SaveToXml();

				StringEncryption encryption = new StringEncryption();

				byte[] encTicket = encryption.EncryptString(xmlDoc.OuterXml, PassportIntegrationSettings.GetConfig().GetDesKey());

				string t = Convert.ToBase64String(encTicket);

				if (returnUrl != null)
				{
					string redirectUrl = returnUrl;

					if (returnUrl.LastIndexOf('?') >= 0)
						redirectUrl += "&";
					else
						redirectUrl += "?";

					redirectUrl += "t=" + HttpUtility.UrlEncode(t);

					Response.Redirect(redirectUrl);
				}
				else
					Helper.ShowTicketInfo(ticket, ticketInfo);
			}
			else
				Helper.ShowTicketInfo(ticket, ticketInfo);
		}
        public void DecryptTest()
        {
            // Arrange
            var pass           = "******";
            var pass2          = "This is a test key";
            var subject        = new StringEncryption(pass);
            var subject2       = new StringEncryption(pass2);
            var originalString = "Testing123!£$";

            // Act
            var encryptedString1 = subject.Encrypt(originalString);
            var encryptedString2 = subject.Encrypt(originalString);
            var decryptedString1 = subject.Decrypt(encryptedString1);
            var decryptedString2 = subject.Decrypt(encryptedString2);

            var encryptedString3 = subject2.Encrypt(originalString);
            var encryptedString4 = subject2.Encrypt(originalString);
            var decryptedString3 = subject2.Decrypt(encryptedString3);
            var decryptedString4 = subject2.Decrypt(encryptedString4);

            // Assert
            Assert.AreEqual(originalString, decryptedString1, "Decrypted string should match original string");
            Assert.AreEqual(originalString, decryptedString2, "Decrypted string should match original string");
            Assert.AreEqual(originalString, decryptedString3, "Decrypted string should match original string");
            Assert.AreEqual(originalString, decryptedString4, "Decrypted string should match original string");
        }
Beispiel #3
0
        public void TestStringToStringEncryption()
        {
            _encryption = new StringEncryption(new AesCryptoServiceProvider());
            string encrypted = _encryption.EncryptStringToString(_password, _key);

            Assert.AreNotEqual(encrypted, _password);
            Assert.NotNull(encrypted);
        }
        public void Decrypt_InvalidPassword_ThrowException(string password)
        {
            string text = "HS.Core.Encryption";

            var encryption = new StringEncryption();

            Assert.Throws <ArgumentException>(() => encryption.Decrypt(text, password));
        }
        public void Decrypt_InvalidText_ThrowException(string text)
        {
            string password = "******";

            var encryption = new StringEncryption();

            Assert.Throws <ArgumentException>(() => encryption.Decrypt(text, password));
        }
Beispiel #6
0
        public void EncryptTest()
        {
            var plainText  = "Hello World";
            var passPhrase = "Key";

            var encryptedText = StringEncryption.Encrypt(plainText, passPhrase);

            Assert.IsNotNull(encryptedText);
        }
Beispiel #7
0
        public static string DecryptCookieValue(HttpCookie cookie, string phrase)
        {
            if (cookie == null)
            {
                return("");
            }

            return(StringEncryption.Decrypt(cookie.Value, phrase));
        }
Beispiel #8
0
        public static HttpCookie CreateCookie(string value, string cookieName, string phrase, double hoursToExpire)
        {
            HttpCookie cookie = new HttpCookie(cookieName);

            cookie.Value   = StringEncryption.Encrypt(value, phrase);
            cookie.Expires = DateTime.Now.AddHours(hoursToExpire);

            return(cookie);
        }
Beispiel #9
0
        public void TestStringDecryption()
        {
            _encryption = new StringEncryption(new AesCryptoServiceProvider());
            byte[] encrypted = _encryption.EncryptStringToBytes(_password, _key);

            string unencrypted = _encryption.DecryptStringFromBytes(encrypted, _key);

            Assert.AreEqual(unencrypted, _password);
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string input = TextBox1.Text;

            //Calling the encrypt function of the StringEncryption class from the LarissaDLL_ClassLibrary created.

            string output = StringEncryption.EnryptString(input);

            Label3.Text = output;
        }
Beispiel #11
0
        private string GetApiString(string baseStr)
        {
            StringEncryption encryptor = new StringEncryption();
            string           query     = baseStr;
            string           str       = _configuration.GetValue <string>("ApiKey");

            query += encryptor.Decode(_configuration.GetValue <string>("ApiKey"), Convert.ToUInt64(_configuration.GetValue <string>("DecryptKey"))) + "&cx=";
            query += encryptor.Decode(_configuration.GetValue <string>("ApiConnString"), Convert.ToUInt64(_configuration.GetValue <string>("DecryptKey"))) + "&q=";
            return(query);
        }
        public void EncryptWork()
        {
            string text     = "HS.Core.Encryption";
            string password = "******";

            var encryption = new StringEncryption();
            var encrypted  = encryption.Encrypt(text, password);

            Assert.AreNotEqual(text, encrypted);
        }
Beispiel #13
0
 public static string GetSessionDataString(string saveName)
 {
     saveName = SESSION_SAVE_DIRECTORY + saveName + ".json";
     if (File.Exists(saveName))
     {
         string rawData       = File.ReadAllText(saveName);
         string decryptedData = StringEncryption.Decrypt(rawData, ENCRYPTION_KEY);
         return(decryptedData);
     }
     return(null);
 }
        protected void Button2_Click(object sender, EventArgs e)
        {
            string input = TextBox1.Text;

            string encrypted = StringEncryption.EnryptString(input);

            //Calling the decrypt function of the StringEncryption class from the LarissaDLL_ClassLibrary created.
            string decrypted = StringDecryption.DecryptString(encrypted);

            Label4.Text = decrypted;
        }
        public void UseDifferentPasswordsFails()
        {
            string text      = "HS.Core.Encryption";
            string password1 = "zaq1@WSX";
            string password2 = "1234qwer";

            var encryption = new StringEncryption();
            var encrypted  = encryption.Encrypt(text, password1);

            Assert.Throws <CryptographicException>(() => encryption.Decrypt(encrypted, password2));
        }
        public void UseCase()
        {
            string text     = "HS.Core.Encryption";
            string password = "******";

            var encryption = new StringEncryption();
            var encrypted  = encryption.Encrypt(text, password);
            var decrypted  = encryption.Decrypt(encrypted, password);

            Assert.AreEqual(text, decrypted);
        }
Beispiel #17
0
        public void DecryptTest()
        {
            var plainText  = "Hello World";
            var passPhrase = "Key";

            var encryptedText = StringEncryption.Encrypt(plainText, passPhrase);

            var decryptedText = StringEncryption.Decrypt(encryptedText, passPhrase);

            Assert.IsTrue(plainText == decryptedText);
        }
Beispiel #18
0
        // change path lol
        public void Start(string _path)
        {
            ModuleDefMD module = ModuleDefMD.Load(@"source.exe");

            StringEncryption stringEncryption = new StringEncryption();

            stringEncryption.Inject(module);
            Renamer renamer = new Renamer();

            renamer.Start(module);
            module.Write(Environment.CurrentDirectory + @"\final.exe");
        }
 public override void ChooseTransformations(Transformations transformations, AssemblyDefinition assembly)
 {
     switch (transformations)
     {
     case Transformations.ProfileEasy:
         stringObfClInj = new StringObfuscationClassInjection(reportManager);
         stringObfClInj.StringCuts(assembly);
         stringEncryption = new StringEncryption(reportManager);
         stringEncryption.EncryptStrings(assembly);
         break;
     }
 }
Beispiel #20
0
        public void TestStringDecryptionDoesNotDecryptForInvalidPassword()
        {
            _encryption = new StringEncryption(new AesCryptoServiceProvider());
            var decryption = new StringEncryption(new AesCryptoServiceProvider());

            byte[]   encrypted = _encryption.EncryptStringToBytes(_password, _key);
            Encoding enc       = new UnicodeEncoding();

            byte[] badPassBytes = enc.GetBytes("2dor39tp");

            decryption.DecryptStringFromBytes(encrypted, badPassBytes);
        }
Beispiel #21
0
        /// <summary>
        /// Exports ICasinoDataReport data as CSV.
        /// </summary>
        /// <param name="casinoDataReport">The casino data report.</param>
        private void ExportCasinoDataReportAsJson(ICasinoDataReport casinoDataReport)
        {
            string casinoDataReportFile = null;

            try
            {
                var exportDirectory = Directory.CreateDirectory(Path.Combine(ExportLocation,
                                                                             DateTime.UtcNow.ToString("yyyy-MM-dd")));

                casinoDataReportFile = Path.Combine(exportDirectory.FullName,
                                                    $"casinoDataReport-{Regex.Replace(casinoDataReport.CasinoCode, @"\s+", "")}-{casinoDataReport.ReportedAt:yyyy-MM-dd-HHmmss}-{casinoDataReport.ReportGuid.ToString()}.txt");
                var casinoDataReportJson = JsonConvert.SerializeObject(casinoDataReport, Formatting.None,
                                                                       new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Auto
                });

                if (!string.IsNullOrWhiteSpace(casinoDataReportJson))
                {
                    File.WriteAllText(casinoDataReportFile, StringEncryption.EncryptString(casinoDataReportJson));
                }

                DataAggregator.SuccessfulCasinoDataReport(casinoDataReport.ReportGuid);
            }
            catch (Exception ex)
            {
                Logger.Warn(
                    $"An unexpected error occurred in LocalDataExporter.ExportCasinoDataReportAsJson method: [{ex.Message}]");
                var innerEx = ex.InnerException;
                while (null != innerEx)
                {
                    Logger.Warn($"[{innerEx.Message}]");
                    innerEx = innerEx.InnerException;
                }

                DataAggregator.UnsuccessfulCasinoDataReport(casinoDataReport.ReportGuid);
                Logger.Warn($"Stack Trace: [{Environment.StackTrace}]");

                // clean up any files created during this failed export
                try
                {
                    if (!string.IsNullOrWhiteSpace(casinoDataReportFile))
                    {
                        File.Delete(casinoDataReportFile);
                    }
                }
                catch (Exception exception)
                {
                    // just log the issue, nothing else needed
                    Logger.Warn(
                        $"LocalDataExporter.ExportCasinoDataReportAsJson: problem deleting [{casinoDataReportFile}] file in catch block [{exception.Message}]");
                }
            }
        }
Beispiel #22
0
    public static void SaveData(string fileName, DataContainer data)
    {
        if (!Directory.Exists(SESSION_SAVE_DIRECTORY))
        {
            Directory.CreateDirectory(SESSION_SAVE_DIRECTORY);
        }
        string json = JsonUtility.ToJson(data);

        string encryptedData = StringEncryption.Encrypt(json, ENCRYPTION_KEY);

        File.WriteAllText(SESSION_SAVE_DIRECTORY + fileName + ".json", encryptedData);
        Debug.Log($"Saved {fileName}");
    }
Beispiel #23
0
        public UserAccount IsLoginValid(string username, string password)
        {
            StringEncryption se            = new StringEncryption();
            string           encpassword   = se.Encrypt(password);
            string           lowerusername = username.ToLower();
            UserAccount      userAccount   = _repository.GetQueryable().Where(x => x.Username.ToLower() == lowerusername && x.Password == encpassword && !x.IsDeleted).FirstOrDefault();

            if (userAccount != null)
            {
                userAccount.Errors = new Dictionary <string, string>();
            }
            return(userAccount);
        }
Beispiel #24
0
 public UserAccount UpdateObjectPassword(UserAccount userAccount, string OldPassword, string NewPassword, string ConfirmPassword)
 {
     if (_validator.ValidUpdateObjectPassword(userAccount, OldPassword, NewPassword, ConfirmPassword, this))
     {
         userAccount.Username = userAccount.Username.Trim();
         StringEncryption se = new StringEncryption();
         //string realpassword = userAccount.Password;
         userAccount.Password = se.Encrypt(NewPassword);
         _repository.UpdateObject(userAccount);
         //userAccount.Password = realpassword; // set back to unencrypted password to prevent encrypting an already encrypted password on the next update
     }
     return(userAccount);
 }
Beispiel #25
0
 public UserAccount CreateObject(UserAccount userAccount)
 {
     userAccount.Errors = new Dictionary <String, String>();
     if (_validator.ValidCreateObject(userAccount, this))
     {
         userAccount.Username = userAccount.Username.Trim();
         StringEncryption se = new StringEncryption();
         //string realpassword = userAccount.Password;
         userAccount.Password = se.Encrypt(userAccount.Password);
         _repository.CreateObject(userAccount);
         //userAccount.Password = realpassword; // set back to unencrypted password to prevent encrypting an already encrypted password on the next update
     }
     return(userAccount);
 }
        public ActionResult PostCategories([FromBody] Password password)
        {
            String configpassword = TriviaConfiguration.Instance.GetPassword();

            var decryptedPassword = StringEncryption.DecryptString(password.Pass);

            if (decryptedPassword == configpassword)
            {
                _repo.PopulateCategories();
                return(Ok());
            }
            else
            {
                return(BadRequest("Access denied!"));
            }
        }
Beispiel #27
0
        private async void BPMain_Load(object sender, EventArgs e)
        {
            var h = Handle;
            await Task.Run(() =>
            {
                _se = new StringEncryption();

                var s = _se.Encrypt("user");

                Init_DT();
                RegisterCOMMLIB(h);
                ImportConfig(_filePath);
                mainBarcodePrinter = new DbBarcodePrinter(_server, _user, _pwd, _db);

                var a = new Action <bool>((ok) => panel1.BackColor = (ok) ? System.Drawing.Color.Green : System.Drawing.Color.Red);

                mainBarcodePrinter.ConnectionChange += new EventHandler <bool>((o, ok) =>
                {
                    if (InvokeRequired)
                    {
                        Invoke(new Action <bool>(a), ok);
                    }
                    else
                    {
                        a(ok);
                    }
                });

                if (InvokeRequired)
                {
                    Invoke(new Action <bool>(a), mainBarcodePrinter.ConnectionOk);
                }
                else
                {
                    a(mainBarcodePrinter.ConnectionOk);
                }

                _bg                     = new BackgroundWorker();
                _bg.DoWork             += new DoWorkEventHandler(Bg_DoWork);
                _bg.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Bg_RunWorkerCompleted);

                AdviseAllDT();
            });

            h = IntPtr.Zero;
        }
        private String doPossibleDecryption(String rdl)
        {
            if (Path.GetExtension(_SourceFile.LocalPath).Equals(".encrypted"))
            {
                try
                {
                    StringEncryption enc = new StringEncryption(Prompt.ShowDialog("Please enter the passkey", "Passkey?"));
                    rdl = enc.Decrypt(rdl);
                }
                catch (Exception)
                {
                    MessageBox.Show(Properties.Resources.MDIChild_doPossibleDecryption_Incorrect_passkey_entered_);
                }
            }

            return(rdl);
        }
 public UserAccount VIsCorrectOldPassword(UserAccount userAccount, string OldPassword, IUserAccountService _userAccountService)
 {
     if (OldPassword == null || OldPassword.Trim() == "")
     {
         userAccount.Errors.Add("Generic", "OldPassword Tidak boleh kosong");
     }
     else
     {
         StringEncryption se             = new StringEncryption();
         string           encOldPassword = se.Encrypt(OldPassword);
         UserAccount      userAccount2   = _userAccountService.GetObjectById(userAccount.Id);
         if (encOldPassword != userAccount2.Password)
         {
             userAccount.Errors.Add("Generic", "Old Password Salah");
         }
     }
     return(userAccount);
 }
        private String doPossibleEncryption(Uri file, String rdl)
        {
            String extension = Path.GetExtension(file.LocalPath);

            if (extension.Equals(".encrypted"))
            {
                StringEncryption enc = new StringEncryption(Prompt.ShowDialog("Please enter passkey", "Passkey?"));
                try
                {
                    rdl = enc.Encrypt(rdl);
                }
                catch (Exception)
                {
                    MessageBox.Show(Properties.Resources.MDIChild_doPossibleEncryption_Unable_to_encrypt_file_);
                }
            }
            return(rdl);
        }