title: Decrypting the Connection String in App.config
body: <p>I have a console application in which I have some connection strings which are encrypted as shown below: </p>
  
  <pre><code>&lt;connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider"&gt;
      &lt;EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
        xmlns="http://www.w3.org/2001/04/xmlenc#"&gt;
        &lt;EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" /&gt;
        &lt;KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"&gt;
          &lt;EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#"&gt;
            &lt;EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" /&gt;
            &lt;KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"&gt;
              &lt;KeyName&gt;Rsa Key&lt;/KeyName&gt;
            &lt;/KeyInfo&gt;
            &lt;CipherData&gt;
              &lt;CipherValue&gt;soemvalue here&lt;/CipherValue&gt;
            &lt;/CipherData&gt;
          &lt;/EncryptedKey&gt;
        &lt;/KeyInfo&gt;
        &lt;CipherData&gt;
          &lt;CipherValue&gt;some valye here&lt;/CipherValue&gt;
        &lt;/CipherData&gt;
      &lt;/EncryptedData&gt;
    &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>I try to access the connection string using the console application like this: </p>
  
  <pre><code>var connectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString; 
  </code></pre>
  
  <p>I get the following error: </p>
  
  <blockquote>
    <p>Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: The RSA key container could not be opened. </p>
  </blockquote>
  
  <p>When I try to access the same connection string from app.config without decryption then it works fine. Is there any problem with the encryption? I thought that after encryption I just have to fetch the connection string in normal manner and it will decrypt automatically.</p>