Encrypting Connection information

Topics: Data Access Application Block
Jun 1, 2007 at 8:48 PM
I am new in vb.net. Now I am learning how to use the Data Access Application Block by following the excercise from Enterprise Library Hands On Lab. I have problem to do exercise 3: Encrypting Connection information. I follow the instruction and run the application then open the config file in notepad. I don't see any changes in config file. It is not encrypted. Can any one tell me why? I am using Data Access Application Block 2.0.
Jun 5, 2007 at 2:53 AM
There is no encryption mechanism in Enterprise Library 2.0, so I don't know what you are referring to. The configuration tool for Enterprise Library 3.1 allows one to encrypt the connection strings via a dropdown menu. See here for more information:

Enterprise Library 3.0 Visual Studio-Integrated Configuration Editor




David Hayden
Microsoft MVP C#
Jun 5, 2007 at 12:58 PM
Thanks for your respond Dave. There is the code copied from the Data Access Block 2.0 Hands On Lab exercise 3 for Encrypting Connection String:

Private Shared Sub ProtectConfiguration()

' TODO: Protect the Connection Strings
Dim provider As String = "RsaProtectedConfigurationProvider"

Dim config As Configuration = Nothing
config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

Dim section As ConfigurationSection = config.ConnectionStrings

If ((section.SectionInformation.IsProtected = False) AndAlso _
(section.ElementInformation.IsLocked = False)) Then

' Protect (encrypt) the "connectionStrings" section.

' Save the encrypted section.
section.SectionInformation.ForceSave = True
End If

End Sub
Jun 5, 2007 at 2:42 PM
I see. I posted something similar that I run in my ASP.NET web applications when I need to encrypt remotely:

Encrypt Connection Strings AppSettings and Web.Config in ASP.NET 2.0 - Security Best Practices

Here is another version of the example in the hands on labs that I have used:

Encrypt ConnectionStrings in App.config

You get this for free in Enterprise Library 3.1 as well as a couple of other features in the DAAB that you may want:

1. System.Transactions Support
2. Batch Updates

If you can, I would just migrate to EntLib 3.1.




David Hayden
Microsoft MVP C#