コード例 #1
0
        public void SaveConfiguration(CurrentUserConfiguration configuration, string password)
        {
            var    jsonConfiguration      = JsonConvert.SerializeObject(configuration);
            string encryptedConfiguration = EncryptingHelper.Encrypt(jsonConfiguration, password);

            FileModification.WriteFile(ConfigurationPath, encryptedConfiguration);
        }
コード例 #2
0
        public void ExceptionIsThrownOnInvalidPassphrase()
        {
            //Arrange & Act
            Action decryptionProcess = () => { EncryptingHelper.Decrypt(_encryptedText, "admin1"); };

            //Assert
            decryptionProcess.Should().Throw <System.Security.Cryptography.CryptographicException>();
        }
コード例 #3
0
        public void DecryptTextCorrectly()
        {
            //Arrange & Act
            string result = EncryptingHelper.Decrypt(_encryptedText, _passphrase);

            //Assert
            result.Should().Be(_decryptedText);
        }
コード例 #4
0
        private void SaveUserConfiguration(CurrentUserConfiguration userConfiguration)
        {
            var    jsonConfiguration      = JsonConvert.SerializeObject(userConfiguration);
            string encryptedConfiguration = EncryptingHelper.Encrypt(jsonConfiguration, _configurationPassword);

            FileModification.CreateFolderIfNotExists($"{_programSettingsPath}\\.backOnTrack");

            FileModification.WriteFile(GetProxyUserConfigurationPath(), encryptedConfiguration);
        }
コード例 #5
0
        public static CurrentUserConfiguration DecryptConfiguration(string encryptedConfigurationContent, string password)
        {
            if (encryptedConfigurationContent != "")
            {
                string configurationContent = EncryptingHelper.Decrypt(encryptedConfigurationContent, password);
                return(JsonConvert.DeserializeObject <CurrentUserConfiguration>(configurationContent));
            }

            return(null);
        }
コード例 #6
0
        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.");
                }
            }
        }
コード例 #7
0
        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);
        }