1- Create an extra ASP.NET page (call it CSEncryDecry, for example) that contains a two BUTTONs. One called "Encrypt" the other called "Decrypt". In the code behind, provide the necessary code shown below.
2- Upload that page to your Website root folder.
3- Click the BUTTON to the perform the Encryption.
4- In order to "physically" confirm the process has been successfully achieved, download the Web.Config file to your local machine and open it with any Text Editor (Note Pad will be nice). If the ConnectionString was Encrypted correctly, you'll read some "rabbish looking" characters.
5- Erease that extra ASP.NET page from your Website root folder. (For security purposes).
6- To Decrypt or Re-Encrypt in the future, upload that ASP.NET file again, do your task, then delete from the website.
Necessary Imports:
Imports System.Web.Configuration
Imports System.Configuration
VB:
To Encrypt:
Protected Sub btn_Encrypt_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_Encrypt.Click
Try
Dim confg As Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
Dim confStrSect As ConfigurationSection = confg.GetSection("connectionStrings")
If Not confStrSect Is Nothing Then
confStrSect.SectionInformation.ProtectSection(provider)
confg.Save()
End If
Catch ex As Exception
End Try
End Sub
To Decrypt:
Protected Sub btn_Decrypt_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_Decrypt.Click
Try
Dim confg As Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
Dim confStrSect As ConfigurationSection = confg.GetSection("connectionStrings")
If Not confStrSect Is Nothing AndAlso confStrSect.SectionInformation.IsProtected Then
confStrSect.SectionInformation.UnprotectSection()
confg.Save()
End If
Catch ex As Exception
End Try
End Sub