加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

加密 – 是ConfigurationManage – > section.SectionInforma

发布时间:2020-12-14 00:51:17 所属栏目:百科 来源:网络整理
导读:在代码中 Configuration config = ConfigurationManager.OpenExeConfiguration (Application.ExecutablePath);ConnectionStringsSection section = config.GetSection("connectionStrings") as ConnectionStringsSection;if (!section.SectionInformation.Is
在代码中
Configuration config = ConfigurationManager.OpenExeConfiguration (Application.ExecutablePath);
ConnectionStringsSection section = config.GetSection("connectionStrings") as ConnectionStringsSection;
if (!section.SectionInformation.IsProtected)
{
    section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
}

当我将应用程序移动到另一台机器时,我遇到了麻烦.

是section.SectionInformation.ProtectSection调用机器依赖,意思是,我不能复制配置文件并在另一台机器上使用它?

是否有机器独立的提供者(DataProtectionConfigurationProvider除外)?

我的应用程序要求它可以在具有相同配置文件的多台计算机上运行(它必须从闪存驱动器运行).

谢谢,
法比奥

Is the section.SectionInformation.ProtectSection call machine dependent,meaning,I cannot copy the config file and use it on another machine ?

是的,就我所知,这是正确的. This article表示密钥存储在每台机器或每个用户的基础上.

Is there a provider (other than DataProtectionConfigurationProvider ) that is machine independet?

不是开箱即用,我所知道的两个提供商(DataProtectionConfigurationProvider和RSAProtectedConfigurationProvider)都有相同的“问题”.我发现了一些提示,RSA提供程序允许跨机器重用密钥,但没有找到任何关于如何实现这一点的示例.

但是,有一种方法可以实现你所需要的,我昨天自己做了,因为我遇到了类似的问题(我需要从网络位置运行应用程序,并且所有客户端都需要共享相同的加密配置文件) .您可以滚动自己的ProtectedConfigurationProvider.以下是一些说明这一概念的链接:

> Implementing a Protected Configuration Provider
> How to: Build and Run the Protected Configuration Provider Example
> Protected Configuration Provider Implementation Example

使用这些文章,我能够构建自己的ProtectedConfigurationProvider,它不依赖于机器或用户,并在应用程序中使用它.我的发布版本中有一个后期构建步骤,可以保护配置部分,因此我只部署它的受保护版本.获取受保护的部分数据可以在其他计算机上正常运行而不会出现任何问题.当然,您必须非常小心如何安全地加密和解密您的部分.有一些例子说明如何做到这一点,this就是我认为的其中一个.

在这三篇文章中没有明确说明的一件事是,如果您不使用ASP.net,如何让您的应用找到您的提供商.将它安装到全局程序集缓存中的常用方法可能不适用于您,因为您声明从闪存驱动器运行应用程序.因此,您需要将其添加到app.config文件中,类似于:

<?xml version="1.0"?>
<configuration>
  ... 
  <configProtectedData defaultProvider="MyEncryptionProvider">
    <providers>
      <add name="MyEncryptionProvider"
        type="MyAssembly.MyEncryptionProvider,MyAssembly,Version=1.0.0.0,Culture=neutral,PublicKeyToken=whatever_the_assembly_token_is" />
    </providers>
  </configProtectedData>
  ...
</configuration>

如果执行加密的程序集与主程序集位于同一路径中,则此方法应该有效.我正在使用已签名的程序集,sn -T {Assembly}将为您提供需要在配置文件中输入的PublicKeyToken.

然后保护一个部分,类似于:

using System.Configuration;

...

Configuration oConfiguration = ConfigurationManager.OpenExeConfiguration(yourExePath);
oSection.SectionInformation.ProtectSection("MyEncryptionProvider");
oSection.SectionInformation.ForceSave = true;
oConfiguration.Save();

我今天测试了它,它使用在开发机器(XP SP3)上加密的配置文件,并在XP SP2,Win7 32Bit和Win7 64Bit上使用.

免责声明

>如果您没有签署装配,则不确定是否有任何效果.>使用风险自负,我不是任何标准的安全专家.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读