文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Web.Config两种加密

Web.Config两种加密

时间:2010-09-03  来源:销直

 

  <configProtectedData defaultProvider="RsaProtectedConfigurationProvider">
    <providers>
      <add name="MyRsaProtectedConfigurationProvider" type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" description="Uses RsaCryptoServiceProvider to encrypt and decrypt" keyContainerName="NetFrameworkConfigurationKey" cspProviderName="" useMachineContainer="true" useOAEP="false"/>
      <add name="DataProtectionConfigurationProvider" type="System.Configuration.DpapiProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" description="Uses CryptProtectData and CryptUnProtectData Windows APIs to encrypt and decrypt" useMachineProtection="true" keyEntropy=""/>
    </providers>
  </configProtectedData>

 

 

有两种加密的方法

1. DataProtectionConfigurationProvider 使用windows内置的密码学技术加密的

2. RsaProtectedConfigurationProvider 使用RSA公钥加解密

以下为使用实例:

 

 Configuration config;
        config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
        ConnectionStringsSection section;//要处理的对象

        section = config.GetSection("connectionStrings") as ConnectionStringsSection;

        if (section.SectionInformation.IsProtected)
        {
            section.SectionInformation.UnprotectSection();
            //注:解密会自动执行(两种加密同一方法解密)
            config.Save();

        }
        else
        {
            section.SectionInformation.ProtectSection(
                    this.DropDownList1.SelectedItem.Text
                );//使用Dropdownlist中用户指定的provider进行加密 "DataProtectionConfigurationProvider"&"RsaProtectedConfigurationProvider" 
            config.Save();

        }

 

 

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载