Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

decrypt connectionString in web.config?

Tags:

c#

I encrypt my connection string in the web.config with this code in my aspx load.

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. 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.

like image 208
user3357141 Avatar asked Apr 01 '14 18:04

user3357141


1 Answers

I found how to do it here 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();   
}
like image 158
user3357141 Avatar answered Oct 25 '22 10:10

user3357141