/// <summary> /// Decrypt a Section in a Configuration File. /// </summary> /// <param name="pathToExe">The path to the exe that owns the configuration file</param> /// <param name="sectionName">The name of the section to decrypt.</param> /// <returns></returns> public CommandExecutionResult DecryptConfigurationSection(string pathToExe, string sectionName) { try { // Open the config and locate the section var config = OpenApplicationConfiguration(pathToExe); var section = GetConfigurationSection(config, sectionName); if (section == null) { return(new CommandExecutionResult(false, "The section '" + sectionName + "' was not found in the configuration.")); } // Already Decrypted if (!section.SectionInformation.IsProtected) { return(CommandExecutionResult.NoOp("Section is already Decrypted.")); } // Decrypt the Section _log.Debug("Decrypting Section"); section.SectionInformation.UnprotectSection(); // Save the Configuration Changes _log.Debug("Saving Configuration"); config.Save(); return(new CommandExecutionResult(true, "Section '" + sectionName + "' Decrypted.")); } catch (Exception ex) { _log.Error(ex); return(new CommandExecutionResult(false, ex.Message)); } }
public override CommandExecutionResult Execute() { var svc = new ConfigurationEncryptionService(); if (!string.IsNullOrWhiteSpace(PathToExe)) { return(svc.DecryptConfigurationSection(PathToExe, ConfigurationEncryptionService.ConnectionStringsSectionName)); } if (!string.IsNullOrWhiteSpace(WebSite)) { throw new NotImplementedException("Web Configurations are not yet supported."); } return(CommandExecutionResult.NoOp()); }
public override CommandExecutionResult Execute() { var svc = new ConfigurationEncryptionService(); if (!string.IsNullOrWhiteSpace(PathToExe)) { return(svc.EncryptConfigurationSection(PathToExe, ConfigurationEncryptionService.ConnectionStringsSectionName, Provider)); } if (!string.IsNullOrWhiteSpace(WebSite)) { return(CommandExecutionResult.Fail("Web Configurations are not currently supported. Please use aspnet_regiis.exe instead.")); } return(CommandExecutionResult.NoOp()); }