简体   繁体   English

解密web.config中的connectionString?

[英]decrypt connectionString in web.config?

I encrypt my connection string in the web.config with this code in my aspx load. 我在我的aspx加载中使用此代码加密web.config中的连接字符串。

protected void Page_Load(object sender, EventArgs e)
{
    Configuration config =      WebConfigurationManager.OpenWebConfiguration("~");

    ConnectionStringsSection connSection = (ConnectionStringsSection)config.GetSection("connectionStrings");

    connSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");

    config.Save();
}

I am newbie with c # and for now what I need is decrypt. 我是c#的新手,现在我需要的是解密。 Any idea how? 知道怎么样?

I could decrypt only one line using following code. 我可以使用以下代码解密一行。

protected void Page_Load(object sender, EventArgs e)
{
    Configuration config = WebConfigurationManager.OpenWebConfiguration("~");

    ConnectionStringsSection connSection = (ConnectionStringsSection)config.GetSection("connectionStrings");

    //connSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
    connSection.SectionInformation.UnprotectSection();

    config.Save();   
}

Thanks. 谢谢。

I found how to do it here https://msdn.microsoft.com/en-us/library/dtkwfdky(v=vs.100).aspx 我发现如何在这里做到这一点https://msdn.microsoft.com/en-us/library/dtkwfdky(v=vs.100).aspx

I could decrypt by only changing one line of the following code: 我只能通过更改以下代码中的一行来解密:

protected void Page_Load(object sender, EventArgs e)
{
    Configuration config = WebConfigurationManager.OpenWebConfiguration("~");

    ConnectionStringsSection connSection = (ConnectionStringsSection)config.GetSection("connectionStrings");
    //connSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
    connSection.SectionInformation.UnprotectSection();

    config.Save();   
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM