title: How to encrypt app.config?
body: <p>Create app.config in wpf (c#)</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;connectionStrings&gt;
      &lt;clear /&gt;
      &lt;add name="Name"
       providerName="MySql.Data"
       connectionString="Server=.net;Uid=;Pwd=H;Database=;charset=utf8;Allow Zero Datetime=true;" /&gt;
    &lt;/connectionStrings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>used code C#:</p>
  
  <pre><code>    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
      ConnectionStringsSection conStr = config.ConnectionStrings;
      if (!conStr.SectionInformation.IsProtected)
      {
          conStr.SectionInformation.ProtectSection("RSAProtectedConfigurationProvider");
          conStr.SectionInformation.ForceSave = true;
          config.Save();
      }
      else
      {
          foreach (ConnectionStringSettings ss in conStr.ConnectionStrings)
              Console.WriteLine(ss);
          Console.Read();
      }
  </code></pre>
  
  <p><code>config.Save();</code> - causes exception:</p>
  
  <blockquote>
    <p>{"Failed to encrypt the section 'connectionStrings' using provider
    'RsaProtectedConfigurationProvider'. The error message from the
    provider: Object already exists .\r\n"}</p>
  </blockquote>