Welcome to Sign in | Join | Help
Home Forums Photos Downloads

Re: Encrypt a Connection String

  •  10-23-2006, 9:25 AM

    Re: Encrypt a Connection String

    ::raises hand:: I do this on my site -- you can also encrypt sql connections!  (REALLY GOOD IDEA)

     create a button and make this its event

    protected void Button1_Click(object sender, EventArgs e)

    {

    ProtectSection("connectionStrings", "DataProtectionConfigurationProvider");

    }

    to unencrypt...

    protected void Button2_Click(object sender, EventArgs e)

    {

    UnprotectSection("connectionStrings");

    }

    functions are the same as given on the link above (for fun, I pasted them below), and don't forget to add System.Web.Configuration

    private void ProtectSection(string sectionName, string provider)

    {

    Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

    ConfigurationSection section = config.GetSection(sectionName);

    if (section != null && !section.SectionInformation.IsProtected)

    {

    section.SectionInformation.ProtectSection(provider);

    config.Save();

    }

    }

     

    private void UnprotectSection(string sectionName)

    {

    Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

    ConfigurationSection section = config.GetSection(sectionName);

    if (section != null && section.SectionInformation.IsProtected)

    {

    section.SectionInformation.UnprotectSection();

    config.Save();

    }

    }


    RileyTech.net
    Trainer video maker guy
    "Where did you find that?" code man

    Yes, I have and frequently wear a fedora :-P
    Filed under: ,
View Complete Thread
Powered by Community Server, by Telligent Systems