private static ClientConfiguration LoadClientConfiguration() { string baseUrl = string.Empty; switch (Settings.Default.ClientType) { case ClientType.TeamCity: baseUrl = Settings.Default.BaseUrlTeamCity; break; case ClientType.Hudson: baseUrl = Settings.Default.BaseUrlHudson; break; case ClientType.Bamboo: baseUrl = Settings.Default.BaseUrlBamboo; break; } return(new ClientConfiguration { Domain = Settings.Default.Domain, Port = Settings.Default.Port, UserName = Settings.Default.UserName, Password = SecureData.Decrypt(Settings.Default.Password), UseSsl = Settings.Default.UseSsl, IgnoreInvalidCertificate = Settings.Default.IgnoreInvalidCertificate, ClientType = Settings.Default.ClientType, BaseUrl = baseUrl }); }
private void LoadSettings() { TextBoxDomain.Text = Settings.Default.Domain; TextBoxPort.Text = Settings.Default.Port == 80 ? string.Empty : Settings.Default.Port.ToString(); TextBoxUserName.Text = Settings.Default.UserName; PasswordBoxPassword.Password = SecureData.Decrypt(Settings.Default.Password); CheckBoxHideInactive.IsChecked = Settings.Default.HideInactive; RadioButtonProtocolHttp.IsChecked = !Settings.Default.UseSsl; RadioButtonProtocolHttps.IsChecked = Settings.Default.UseSsl; ComboBoxRefreshInterval.Items.Cast <ComboBoxItem>() .Where(comboBoxItem => (string)comboBoxItem.Content == Settings.Default.RefreshInterval.ToString()) .Select(comboBoxItem => comboBoxItem).Single().IsSelected = true; ComboBoxColumnsNumber.Items.Cast <ComboBoxItem>() .Where(comboBoxItem => (string)comboBoxItem.Content == Settings.Default.NumberOfColumns.ToString()) .Select(comboBoxItem => comboBoxItem).Single().IsSelected = true; ComboBoxHideInactive.Items.Cast <ComboBoxItem>() .Where(comboBoxItem => (string)comboBoxItem.Content == Settings.Default.HideInactiveWeeks.ToString()) .Select(comboBoxItem => comboBoxItem).Single().IsSelected = true; ComboBoxCIType.Items.Cast <ComboBoxItem>() .Where(comboBoxItem => (string)comboBoxItem.Content == Settings.Default.ClientType.ToString()) .Select(comboBoxItem => comboBoxItem).Single().IsSelected = true; }
public void SecureData_Asymmetric() { string privateKey = AsymmetricCrypto.CreatePrivateKey(CryptoAlgorithm.RSA, 1024); string publicKey = AsymmetricCrypto.GetPublicKey(CryptoAlgorithm.RSA, privateKey); byte[] plainText; byte[] cipherText; plainText = new byte[] { 0, 1, 2, 3 }; cipherText = SecureData.Encrypt(publicKey, plainText, CryptoAlgorithm.AES, 256); CollectionAssert.AreNotEqual(plainText, cipherText); CollectionAssert.AreEqual(plainText, SecureData.Decrypt(privateKey, cipherText)); plainText = new byte[] { 0, 1, 2, 3 }; cipherText = SecureData.Encrypt(publicKey, plainText, CryptoAlgorithm.AES, 256, 1000); Assert.IsTrue(cipherText.Length >= 1000); plainText = new byte[0]; cipherText = SecureData.Encrypt(publicKey, plainText, CryptoAlgorithm.AES, 256); CollectionAssert.AreNotEqual(plainText, cipherText); CollectionAssert.AreEqual(plainText, SecureData.Decrypt(privateKey, cipherText)); plainText = new byte[2000000]; for (int i = 0; i < plainText.Length; i++) { plainText[i] = (byte)i; } cipherText = SecureData.Encrypt(publicKey, plainText, CryptoAlgorithm.AES, 256); CollectionAssert.AreNotEqual(plainText, cipherText); CollectionAssert.AreEqual(plainText, SecureData.Decrypt(privateKey, cipherText)); }
public void SecureData_Symmetric() { string privateKey = AsymmetricCrypto.CreatePrivateKey(CryptoAlgorithm.RSA, 1024); string publicKey = AsymmetricCrypto.GetPublicKey(CryptoAlgorithm.RSA, privateKey); SymmetricKey argsEncrypt; SymmetricKey argsDecrypt; byte[] asymPlain; byte[] asymCipher; byte[] symPlain; byte[] symCipher; asymPlain = new byte[] { 0, 1, 2, 3 }; asymCipher = SecureData.Encrypt(publicKey, asymPlain, CryptoAlgorithm.AES, 256, 1000, out argsEncrypt); CollectionAssert.AreEqual(asymPlain, SecureData.Decrypt(privateKey, asymCipher, out argsDecrypt)); symPlain = new byte[] { 10, 20, 30, 40 }; symCipher = SecureData.Encrypt(argsEncrypt, symPlain, 100); Assert.IsTrue(symCipher.Length >= 100); CollectionAssert.AreEqual(symPlain, SecureData.Decrypt(argsDecrypt, symCipher)); }
public void Decrypt_EncryptedString_ShouldMatchExpectedString() { string encryptedString = SecureData.Encrypt("Password"); SecureData.Decrypt(encryptedString).ShouldBeEqual("Password"); }
public void Decrypt_EncryptedDataIsNull_ShouldBeNull() { SecureData.Decrypt(null).ShouldBeNull(); }