title: ProtectedConfigurationProvider using Rsa and x509 certificate
body: <p>I'm new to this so please bear with me. I'm trying to encrypt/decrypt a .config section using <strong>RsaProtectedConfigurationProvider</strong></p>
  
  <p>Please correct me if I'm wrong but from what i've been reading I need to do the following:</p>
  
  <ol>
  <li><p>Get a certificate and a public key from that certificate</p>
  
  <pre><code>X509Certificate2 cert = new X509Certificate2(pathToCert, "password");
  RSACryptoServiceProvider rsa = cert.PrivateKey as RSACryptoServiceProvider;
  </code></pre></li>
  <li><p>Load this info to Container:
  Not sure how to do it as the sample below does not account for certificates</p></li>
  </ol>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/tswxhw92%28en-us,VS.80%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/tswxhw92(en-us,VS.80).aspx</a></p>
  
  <pre><code>    // Create the CspParameters object and set the key container 
      // name used to store the RSA key pair.
      CspParameters cp = new CspParameters();
      cp.KeyContainerName = "MySuperAwesomeKeyContainer";
  
      // Create a new instance of RSACryptoServiceProvider that accesses
      // the key container MyKeyContainerName.
      RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp);
  </code></pre>
  
  <ol>
  <li>Then have the same Container name specified in my App.Config:</li>
  </ol>
  
  <blockquote>
  <pre><code>&lt;configProtectedData&gt;
  &lt;providers&gt;
   &lt;clear/&gt;
    &lt;add name="MyProvider"
    type="System.Configuration.RsaProtectedConfigurationProvider"
    keyContainerName="MySuperAwesomeKeyContainer"
    useMachineContainer="true" /&gt;
  &lt;/providers&gt;
  &lt;/configProtectedData&gt;
  </code></pre>
  </blockquote>
  
  <ol>
  <li>Then just run this code that will use that KeyContainer and encrypt/decrypt it:</li>
  </ol>
  
  <blockquote>
  <pre><code>....
  string provider = "MyProvider";
  // Protect the section.
  connStrings.SectionInformation.ProtectSection(provider);
  </code></pre>
  </blockquote>
  
  <p>Is this correct?. If so, how would I do it?? Not sure how to get those keys from certificate and load them in a KeyContainer.</p>
  
  <p>thanks</p>