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

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
    Member

    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.