Thursday, April 2, 2009

Encrypt and decrypt config file of .net window application

/*Thsi code can be used to encrypt and decrypt the config file of window application developed in .net for security purpose*/
static void EncryptionandDecyption(string exeConfigName)
{
try
{
Configuration config = ConfigurationManager.OpenExeConfiguration(exeConfigName);
AppSettingsSection section = config.GetSection("appSettings") as AppSettingsSection;
if (section.SectionInformation.IsProtected)
{
//section.SectionInformation.UnprotectSection();
}
else
{
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
}
config.Save();
}
catch (Exception ex)
{
}
}

For Further detail refer to these books.

Programming .NET 3.5Programming .NET Components, 2nd EditionProgramming Microsoft .NET (Core reference)Beginning ASP.NET 3.5: In C# and VB (Programmer to Programmer)Pro C# 2010 and the .NET 4 Platform, Fifth Edition

No comments:

Post a Comment