示例#1
0
 private void btnDecrypt_Click(object sender, EventArgs e)
 {
     if (_currentConfiguration == null)
     {
         return;
     }
     try
     {
         string res = CmdHelper.Shell(CmdHelper.GetAspNetRegIisPath(), $"-pdf {cbxConfigSections.SelectedValue} {Path.GetDirectoryName(_currentFileName)}");
         txtOutput.Text += res + Environment.NewLine;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error: " + ex.Message);
     }
 }
示例#2
0
        private void btbDelete_Click(object sender, EventArgs e)
        {
            if (!containerNameValid())
            {
                return;
            }
            if (MessageBox.Show(string.Format(
                                    "Deleting key container may cause web.config unable to be decrypted, \nAre you sure to delete '{0}'?",
                                    txtContainerName.Text),
                                "Delete Confirmation", MessageBoxButtons.YesNo)
                == System.Windows.Forms.DialogResult.No)
            {
                return;
            }
            string res = CmdHelper.Shell(getAspNetRegIisPath(), string.Format("-pz \"{0}\"", txtContainerName.Text));

            txtResult.Text = res;
        }
示例#3
0
 private void LoadKeyContainers()
 {
     cbxContanerKeys.DataSource = CmdHelper.GetKeyContainers();
 }
示例#4
0
        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            if (_currentConfiguration == null)
            {
                return;
            }
            try
            {
                XElement xdoc = XElement.Load(_currentFileName);
                var      configProtectedDataSection = xdoc.Elements().Where(x => x.Name == "configProtectedData");
                var      providerName     = configProtectedDataSection.Descendants("add").First().Attribute("name").Value;
                var      keyContainerName = configProtectedDataSection.Descendants("add").First().Attribute("keyContainerName").Value;

                string res = CmdHelper.Shell(CmdHelper.GetAspNetRegIisPath(), $"-pef {cbxConfigSections.SelectedValue} {Path.GetDirectoryName(_currentFileName)} -prov {providerName}");
                txtOutput.Text += res + Environment.NewLine;

                //ConfigurationSection currSection = currConf.ConnectionStrings;
                //ConfigurationSection currSection = _currentConfiguration.GetSection(cbxConfigSections.SelectedItem.ToString());
                //string keyContainerName = txtKeyContainerName.Text;
                //if (string.IsNullOrEmpty(keyContainerName))
                //    keyContainerName = "RsaProtectedConfigurationProvider";
                //else
                //{
                //    //Create custom provider
                //    ProtectedConfigurationSection pdSec = _currentConfiguration.GetSection("configProtectedData") as ProtectedConfigurationSection;
                //    if (pdSec == null)
                //    {
                //        pdSec = new ProtectedConfigurationSection();
                //        _currentConfiguration.Sections.Add("configProtectedData", pdSec);
                //    }
                //    bool found = false;
                //    foreach (ProviderSettings p in pdSec.Providers)
                //        if (p.Name == keyContainerName) found = true;
                //    if (!found)
                //    {
                //        ProviderSettings ps = new ProviderSettings
                //        {
                //            Name = keyContainerName,
                //            Type = "System.Configuration.RsaProtectedConfigurationProvider"
                //        };
                //        ps.Parameters.Add("keyContainerName", keyContainerName);
                //        ps.Parameters.Add("useMachineContainer", "true");
                //        pdSec.Providers.Add(ps);
                //        //Note: A new key container will be created silently, if the key container name doesn't exist.
                //        //      But the auto created key container is not exportable and inappropriate for shared key among
                //        //      web farm servers.  Please use RSA key manager to create exportable key container for web farm
                //        //      scenarios.
                //    }
                //}

                //if (btnExecute.Text == "Encrypt")
                //    currSection.SectionInformation.ProtectSection(keyContainerName);
                //else
                //    currSection.SectionInformation.UnprotectSection();
                //_currentConfiguration.Save(ConfigurationSaveMode.Full);
                wbEditor.Navigate(_currentFileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }