Here is what I ended up with ...
I used WiX and DTF to create custom Action managed code to encrypt this section of the configuration file:
public static void EncryptConfig(Session session) { var configPath = session["APPCONFIGPATH"]; var sectionToEncrypt = session["SECTIONTOENCRYPT"]; var fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = configPath; var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); ConfigurationSection section = configuration.GetSection(sectionToEncrypt); if (!section.SectionInformation.IsProtected) { section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider"); section.SectionInformation.ForceSave = true; configuration.Save(ConfigurationSaveMode.Modified); } }
Part of my lack of understanding that caused this question did not know that you can safely create custom actions in managed code using DTF. Documentation is allowed in DTF, but once you get it, it's great.
I found that this only works if I planned my own action after InstallFinalize.
Here is the WiX configuration for this to happen:
<InstallExecuteSequence> <Custom Action="EncryptConfigurationFiles" After="InstallFinalize" /> </InstallExecuteSequence> <Fragment> <Binary Id="YourProject.CustomActions.dll" SourceFile="$(var.YourProject.CustomActions.TargetDir)$(var.YourProject.CustomActions.TargetName).CA.dll" /> <CustomAction Id="EncryptConfigurationFiles" BinaryKey="YourProject.CustomActions.dll" DllEntry="EncryptConfig" Return="check" /> </Fragment>
These blogs / sites helped me get there, and most of the code above was derived from them:
http://geekswithblogs.net/afeng/Default.aspx http://blog.torresdal.net/2008/10/24/WiXAndDTFUsingACustomActionToListAvailableWebSitesOnIIS.aspx http://blogs.msdn.com/jasongin/archive/2008/07/ 09 / votive-project-platform-configurations.aspx
@PITADeveloper ... Thanks for the answer. I found that I did not need to download the assembly to encrypt the configuration file.
If you use this, you should use try catch and return an ActionResult ... The above pseudo code.
Finally, I am using DataProtectionConfigurationProvider. For the RSA provider, I think there are a few more hoops that you can jump over.
Hope this helps someone!
Jasons
source share