title: aspnet_regiis web.config encryption [Error message from the provider: Bad Data.]
body: <p>I'm trying to encrypt a web app's web.config, but this application exists on 2 different environments (stage, production), each of which should use a different key container.</p>
  
  <p>So I'm using this encryption header on my stage config:</p>
  
  <pre><code>&lt;configProtectedData defaultProvider="ApplicationProvider"&gt;
  &lt;providers&gt;
    &lt;add name="ApplicationProvider"
      type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
      keyContainerName="ApplicationStageKeys"
      useMachineContainer="true"
      useOAEP="true"/&gt;
  &lt;/providers&gt;
  </code></pre>
  
  <p></p>
  
  <p>And this header on my production config:</p>
  
  <pre><code>&lt;configProtectedData defaultProvider="ApplicationProvider"&gt;
  &lt;providers&gt;
    &lt;add name="ApplicationProvider"
      type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
      keyContainerName="ApplicationProductionKeys"
      useMachineContainer="true"
      useOAEP="true"/&gt;
  &lt;/providers&gt;
  </code></pre>
  
  <p></p>
  
  <p>Encryption works fine but everytime I try to decrypt, I'm getting the following error which leaves far too much to the imagination....</p>
  
  <pre><code>C:\Windows\Microsoft.NET\Framework\v2.0.50727&gt;aspnet_regiis -pdf connectionStrings C:\Temp
  
  Decrypting configuration section...
  Failed to decrypt using provider 'ApplicationProvider'. Error message from the provider: Bad Data.
  (C:\Temp\web.config line 75)
  
  Bad Data.
  
  Failed!
  </code></pre>
  
  <p>I've imported the keys on each server and set up ACLs for both but still no joy, any else ever have this problem?</p>