Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / security

Encrypt Connection String in web.config

2.33/5 (2 votes)
9 Feb 2015CPOL 9.8K  
In this post we will learn how to encrypt connection string in web.config

In this post we will learn how to encrypt connection string in web.config

Implementation

  1. RunDeveloper Command Prompt for VS2013 as Administrator
  2. Change directory to Microsoft .NET Framework Folder
  3. Choose .Net framework folder v4.0.30319
  4. Create a website in the IIS
  5. Register your web application using aspnet_regiis command
Image 1
Developer Command Prompt for VS2013
Image 2
Encrypt Web Config

Image 3

Image 4

Now look at Encrypted web config file

Image 5

web config encrypt

Encrypt  Connection String in web.config Commands

C:\Windows\system32>cd..

C:\Windows>cd Microsoft.NET

C:\Windows\Microsoft.NET>cd Framework

C:\Windows\Microsoft.NET\Framework>cd v4.0.30319

C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis.exe -site "EncryptDemo" -app "/" -pe "connectionStrings"

aspnet_regiis.exe -site "NameoftheSite" -app "/" -pe "EncryptingTag"

Decrypt  Connection String in web.config Commands

From the above command change -pe to -pd to decrypt

aspnet_regiis.exe -site "EncryptDemo" -app "/" -pd "connectionStrings"
C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis.exe -site "EncryptDemo" -app "/" -pd "connectionStrings"

The post Encrypt Connection String in web.config appeared first on Venkat Baggu Blog.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)