title: how to read encrypted app.config appSettings in win console application?
body: <p>EDIT: This question made no sense. I mixed .vshost.config with exe.config. What to do with this?</p>
  
  <p>Program.cs main:</p>
  
  <pre><code>databaseName = System.Configuration.ConfigurationManager.AppSettings["DatabaseName"];
  databaseUser = System.Configuration.ConfigurationManager.AppSettings["DatabaseUser"];
  databasePwd = System.Configuration.ConfigurationManager.AppSettings["DatabasePassword"];
  port = System.Configuration.ConfigurationManager.AppSettings["Port"];
  logDirectory = System.Configuration.ConfigurationManager.AppSettings["LogDirectory"];
  strLogLevel = System.Configuration.ConfigurationManager.AppSettings["LogLevel"];
  
  EncryptConfigSection("appSettings");
  </code></pre>
  
  <p>This is how I encrypt the file:</p>
  
  <pre><code>private static void EncryptConfigSection(string sectionKey)
  {
          Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
          ConfigurationSection section = config.GetSection(sectionKey);
  
          if (section != null)
          {
              if (!section.SectionInformation.IsProtected)
              {
                  if (!section.ElementInformation.IsLocked)
                  {
                      section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
                      section.SectionInformation.ForceSave = true;
  
                      config.Save(ConfigurationSaveMode.Full);
                  }
              }
          }
      }
  </code></pre>
  
  <p>The file gets duplicated and encrypted just like in the examples I found in web:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
      &lt;appSettings configProtectionProvider="DataProtectionConfigurationProvider"&gt;
          &lt;EncryptedData&gt;
             &lt;CipherData&gt;
  &lt;CipherValue&gt;AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAvsQ9Wtc58EC5EZCEq91EogQAAAACAAAAAAADZgAAwAAAABAAAClVHhpR5xAw4KFNyrANtavAAAAAASAAACgAAAAEAAAABHkhg2ztiY3bdWhTG9iy6twAAAAF5mAHt7oDQWCgc1iLL2hYUJZgmquU8XsojjqXVQdV1CaW3XEBXBDhN30DEZizP3F5rGGMCjL9CVjHfsPAfvVYyRHCcup22BoByb5y/MDujaASpaWZYcdxSxLijT/Zq3zB8hiWyWPruY0G7emYEOq/xQAAADkgStCMABwo3oZx/VXHD41wrsjXg==&lt;/CipherValue&gt;
          &lt;/CipherData&gt;
      &lt;/EncryptedData&gt;
  &lt;/appSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>But next time I start it, I can't read it. All read values are null. I naturally removed the original, unencrypted file from the folder.</p>