zoukankan      html  css  js  c++  java
  • web.config 连接字符串 加密解密,代码方式

    //对 web.config 的加密解密

    //如果要加密 appSettings 把 connectionStrings 改为 appSettings 就可以

    <appSettings>
     <add key="con" value="server=.;uid=sa;pwd=;database=demo"/>
    </appSettings>
    <connectionStrings>
     <add name="con" connectionString="server=.;uid=sa;pwd=;database=demo" />
    </connectionStrings>

    //DPAPI加密解密
    protected void btnPdfPefDPAPI_Click(object sender, EventArgs e)
    {
     Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
     ConfigurationSection configSection = config.GetSection("connectionStrings");
     //如果已经加密,则进行解密
            if (configSection.SectionInformation.IsProtected)
            {
                configSection.SectionInformation.UnprotectSection();
                config.Save();
            }
     //加密
            else
            {
                configSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
                config.Save();
            }
    }


    //RSA加密解密
    protected void btnPdfPefRSA_Click(object sender, EventArgs e)
    {
     Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
     ConfigurationSection configSection = config.GetSection("connectionStrings");
     ////如果已经加密,则进行解密
            if (configSection.SectionInformation.IsProtected)
            {
                configSection.SectionInformation.UnprotectSection();
                config.Save();
            }
     //加密
            else
            {
                configSection.SectionInformation.ProtectSection("RSAProtectedConfigurationProvider");
                config.Save();
            }
    }

    --蛮基础的一些东西,备忘用的.

  • 相关阅读:
    Atitit.atiRI  与 远程调用的理论and 设计
    Atitit.提升 升级类库框架后的api代码兼容性设计指南
    Atitit.研发管理软件公司的软资产列表指南
    Atitit.软件开发的三层结构isv金字塔模型
    Atitit.加密算法ati Aes的框架设计
    Atittit.研发公司的组织架构与部门架构总结
    IIS HTTP Error 500.24
    Visual Studio 快捷键
    软件学习遐想
    navigator属性
  • 原文地址:https://www.cnblogs.com/tian_z/p/1792161.html
Copyright © 2011-2022 走看看