public void SaveConfiguration(CurrentUserConfiguration configuration, string password) { var jsonConfiguration = JsonConvert.SerializeObject(configuration); string encryptedConfiguration = EncryptingHelper.Encrypt(jsonConfiguration, password); FileModification.WriteFile(ConfigurationPath, encryptedConfiguration); }
public void ExceptionIsThrownOnInvalidPassphrase() { //Arrange & Act Action decryptionProcess = () => { EncryptingHelper.Decrypt(_encryptedText, "admin1"); }; //Assert decryptionProcess.Should().Throw <System.Security.Cryptography.CryptographicException>(); }
public void DecryptTextCorrectly() { //Arrange & Act string result = EncryptingHelper.Decrypt(_encryptedText, _passphrase); //Assert result.Should().Be(_decryptedText); }
private void SaveUserConfiguration(CurrentUserConfiguration userConfiguration) { var jsonConfiguration = JsonConvert.SerializeObject(userConfiguration); string encryptedConfiguration = EncryptingHelper.Encrypt(jsonConfiguration, _configurationPassword); FileModification.CreateFolderIfNotExists($"{_programSettingsPath}\\.backOnTrack"); FileModification.WriteFile(GetProxyUserConfigurationPath(), encryptedConfiguration); }
public static CurrentUserConfiguration DecryptConfiguration(string encryptedConfigurationContent, string password) { if (encryptedConfigurationContent != "") { string configurationContent = EncryptingHelper.Decrypt(encryptedConfigurationContent, password); return(JsonConvert.DeserializeObject <CurrentUserConfiguration>(configurationContent)); } return(null); }
public void LoadCurrentUserConfiguration() { if (!FileModification.FileExists(GetProxyUserConfigurationPath())) { throw new WebProxyNoProfilesFileException($"WebProxy file \"{GetProxyUserConfigurationPath()}\" does not exist."); } else { string encryptedConfigurationContent = FileModification.ReadFile(GetProxyUserConfigurationPath()); bool fileIsBroken = false; if (encryptedConfigurationContent != "") { try { string configurationContent = EncryptingHelper.Decrypt(encryptedConfigurationContent, _configurationPassword); var configuration = JsonConvert.DeserializeObject <CurrentUserConfiguration>(configurationContent); ApplyUserConfiguration(configuration, false); } catch (Exception) { fileIsBroken = true; } } else { fileIsBroken = true; } if (fileIsBroken) { throw new WebProxyBrokenProfileConfigurationException($"WebProxy file \"{GetProxyUserConfigurationPath()}\" is broken."); } } }
public void EverytimeADifferentOutputForTheSamePassPhrase() { //Arrange & Act string encryptedTextForFirstEncryption = EncryptingHelper.Encrypt(_decryptedText, _passphrase); string decryptedTextForFirstEncryption = EncryptingHelper.Decrypt(encryptedTextForFirstEncryption, _passphrase); string encryptedTextForSecondEncryption = EncryptingHelper.Encrypt(_decryptedText, _passphrase); string decryptedTextForSecondEncryption = EncryptingHelper.Decrypt(encryptedTextForSecondEncryption, _passphrase); string encryptedTextForThirdEncryption = EncryptingHelper.Encrypt(_decryptedText, _passphrase); string decryptedTextForThirdEncryption = EncryptingHelper.Decrypt(encryptedTextForThirdEncryption, _passphrase); //Assert encryptedTextForFirstEncryption.Should().NotBe(encryptedTextForSecondEncryption); encryptedTextForFirstEncryption.Should().NotBe(encryptedTextForThirdEncryption); encryptedTextForSecondEncryption.Should().NotBe(encryptedTextForThirdEncryption); decryptedTextForFirstEncryption.Should().Be(_decryptedText); decryptedTextForSecondEncryption.Should().Be(_decryptedText); decryptedTextForThirdEncryption.Should().Be(_decryptedText); }