如何加密app.config文件部分在安装过程中使用维克斯? [英] How do I encrypt app.config file sections during install with WiX?

查看:214
本文介绍了如何加密app.config文件部分在安装过程中使用维克斯?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到了一个例子安装过程中加密web.config中的此处,但我的应用程序是一个Windows服务。该 aspnetreg_iis 方法仅适用于web.config文件中。

I have found an example for encrypting a web.config during installation here, but my app is a windows service. The aspnetreg_iis method works only for web.config files.

我知道如何编程加密的配置文件,但我不认为我能做到这一点使用WiX的。我错了吗?任何想法?

I know how to programatically encrypt the config file, but I don't think I can do that using WiX. Am I wrong? Any ideas?

推荐答案

下面是我结束了...

Here is what I ended up with...

我用维克斯和DTF创建一个托管C自定义操作$ C $到配置文件的指定部分加密:

I used WiX and DTF to created a managed code Custom Action to encrypt a given section of a config 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);

        }
    }

我缺乏了解,促使这个问题是不知道,你可以安全地创建使用DTF在管理code自定义操作部分。文档是稀疏的DTF,但一旦你得到它的工作,这是伟大的。

Part of my lack of understanding that prompted this question was not knowing that you can safely create custom actions in managed code using DTF. Documentation is sparse on DTF, but once you get it working, it is great.

我发现,这只是如果我计划后InstallFinalize,自定义操作的工作

I found that this only worked if I scheduled the custom action after InstallFinalize.

下面是维克斯config来做到这一点:

Here is the WiX config to make it 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>

这些博客/网站帮助我到达那里和很多的code从上面从中获得的:

These blogs/sites helped me get there and much of the code from above was derived from them:

http://geekswithblogs.net/afeng/Default.aspx <一href="http://blog.torresdal.net/2008/10/24/WiXAndDTFUsingACustomActionToListAvailableWebSitesOnIIS.aspx" rel="nofollow">http://blog.torresdal.net/2008/10/24/WiXAndDTFUsingACustomActionToListAvailableWebSitesOnIIS.aspx 的http://blogs.msdn.com/jasongin/archive/2008/07/09/votive-project-platform-configurations.aspx

@PITADeveloper ...感谢您的答复。我发现,我并不需要加载组件的配置文件进行加密。

@PITADeveloper... Thanks for the response. I found that I did not need to load the assembly to encrypt the config file.

如果你使用这个,你应该使用一个尝试捕捉并返回一个ActionResult ......以上是伪code。

If you use this, you should use a try catch and return an ActionResult... The above is pseudo-code.

最后,我使用了DataProtectionConfigurationProvider。对于RSA提供者,我认为有一对夫妇更箍通过跳跃。

Finally, I'm using the DataProtectionConfigurationProvider. For the RSA Provider, I think there are a couple more hoops to jump through.

我希望这可以帮助别人!

I hope this helps someone!

这篇关于如何加密app.config文件部分在安装过程中使用维克斯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆