Encrypt or Decrypt Connection Strings in web.config file using ASP.NET

Home Forums Web Development ASP.Net Encrypt or Decrypt Connection Strings in web.config file using ASP.NET

This topic contains 0 replies, has 2 voices, and was last updated by  Nitesh 5 years, 8 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3431

    Nitesh
    Member

    How can i Encrypt or Decrypt Connection Strings in web.config file using ASP.NET

    #3436

    Pavan
    Moderator

    Hi Nitesh,
    Encrypt and Decrypt Connection Strings is very usefully for security point.Like when we are developing a application which secured then connection string Encrypt and Decrypt is one of steps.

    Define these string at top of page before page load.

    
    string provider = "RSAProtectedConfigurationProvider";
    string section = "connectionStrings";
    
    

    Encrypt connection string code below:

    
      public void Encrypt_connection()
        {
    
            Configuration confg = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
            ConfigurationSection configSect = confg.GetSection(section);
            if (configSect != null)
            {
                configSect.SectionInformation.ProtectSection(provider);
                confg.Save();
            }
        }
    
    

    Decrypt connection string code below:

    
    
     public void Decrypt_connection()
        {
            Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
            ConfigurationSection configSect = config.GetSection(section);
            if (configSect.SectionInformation.IsProtected)
            {
                configSect.SectionInformation.UnprotectSection();
                config.Save();
            }
        }
    
    
    #3437

    Nitesh
    Member

    thanx a ton pawan.
    it just used the same code in my website and it wordked very first time
    thanx again

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.