Hi,
I was looking a simple way to be able to encrypt and decrypt my Connection Strings. I searched in the net but all i could find was Encrypting and decrypting Connection Strings using aspnet_regiis utility or by creating custom Encryption and decryption classes.
Finally I could a very good way to do encryption and decryption using .NET class library. You can find the video of the tutorial in
asp.net , Videos section (Video is called ASP.NET Tips and Tricks) or read it
HERE .
I am placing a sample code in following lines of code as well.
// Encryption
Configuration config= WebConfigurationManager . OpenWebConfiguration ( Request . ApplicationPath );
ConfigurationSection configuration = config.GetSection ("connectionStrings");
if ( configuration != null )
{
if ( ! configuration.SectionInformation.IsProtected )
{
configuration . SectionInformation . ProtectSection ( "DataProtectionConfigurationProvider" );
config . Save ( );
}
}
// Decryption
Configuration config= WebConfigurationManager . OpenWebConfiguration ( Request . ApplicationPath );
ConfigurationSection configuration = config . GetSection ( "connectionStrings" );
if ( configuration != null )
{
if ( configuration . SectionInformation . IsProtected )
{
configuration . SectionInformation . UnprotectSection ( );
config . Save ( );
}
}