title: Override default algorithm in RSA object to support OaepSHA256 padding
body: <p>Creating <code>RSA</code> or <code>RSACryptoServiceProvider</code> object in .Net 4.6 is defaulting <code>KeyExchangeAlgorithm</code> <code>RSA-PKCS1-KeyEx</code> which supports only <code>OaepSHA1</code> padding. </p>
  
  <p>Getting "Specified padding mode is not valid for this algorithm" on trying to use other padding like "OaepSHA256".</p>
  
  <p>Is there a way to override algorithm in RSA object to an algorithm that supports this padding to make it supportive for all paddings.</p>
  
  <p><a href="https://i.stack.imgur.com/zm4uL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zm4uL.png" alt="enter image description here"></a></p>
  
  <p><strong>UPDATE</strong>
  RSACng works. In my scenario I am using containerkey to store private key in the machine using RSACryptoServiceProvider to retrieve private key when required using containerkey name. As a workaround to use RSACng I am importing properties exporting from RSACryptoServiceProvider object like shown below. Is there a better way to do this?   </p>
  
  <pre><code>using (var rsa = new RSACryptoServiceProvider(cspParams))
              {
                  using(var rsaCng = new RSACng())
                  {
                      rsaCng.ImportParameters(rsa.ExportParameters(true));
  
                      decryptedResult = rsaCng.Decrypt(encryotedText, RSAEncryptionPadding.OaepSHA256)
                  }
              }
  </code></pre>