Web.Config encryption using RsaProtectedConfigurationProvider - “Bad Data” error

前端 未结 7 1823
执笔经年
执笔经年 2021-02-13 02:46

I am attempting to encrypt connection string values in the Web.Config file for an ASP.NET 2.0 web application, following the procedure described on MSDN. Using the RsaProtectedC

相关标签:
7条回答
  • 2021-02-13 03:45

    This is another way to encrypt and decrypt coonection string check it if you are using vs2010 then open vs2010 with run as administrator

    string provider = "RSAProtectedConfigurationProvider";
    
    string section = "connectionStrings"; 
    
    protected void btnEncrypt_Click(object sender, EventArgs e) 
    
    {
    
       Configuration confg =
       WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
    
       ConfigurationSection configSect = confg.GetSection(section);
    
       if (configSect != null)
    
       {
          configSect.SectionInformation.ProtectSection(provider);
          confg.Save();
    
       }
    
    }
    protected void btnDecrypt_Click(object sender, EventArgs e)
    {
        Configuration config =
            WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
        ConfigurationSection configSect = config.GetSection(section);
        if (configSect.SectionInformation.IsProtected)
        {
            configSect.SectionInformation.UnprotectSection();
            config.Save();
        }
    }
    
    0 讨论(0)
提交回复
热议问题