te paso un code que yo utilizo
Código:
/// <summary>
/// Encripta la información que aparece en los appsettings de la aplicacion
/// </summary>
static void EncryptConnectionStrings()
{
Configuration config = ConfigurationManager.
OpenExeConfiguration
(ConfigurationUserLevel.None);
ConfigurationSection section =
config.GetSection("connectionStrings");
if (section != null)
{
if (!section.IsReadOnly())
{
if (!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection
("DataProtectionConfigurationProvider");
section.SectionInformation.
ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
}
}
}