title: Decryption with RSA/ECB/PKCS1Padding
body: <p>Following  tag is a part of SAML response. I have to decrypt following CipherValue.
  I pass CipherValue ( string ) to following function but it did not return correct value, what am I doing wrong?</p>
  
  <p>Documentation says : </p>
  
  <ol>
  <li><p>Obtain the private key from the certificate. </p></li>
  <li><p>Decrypt the encrypted key using RSA/ECB/PKCS1Padding.</p></li>
  </ol>
  
  <p>( key is following value)</p>
  
  <pre><code>private string RSADecryption(string dataToDecrypt) 
  {
  
    String certificateLocation = ConfigurationManager.AppSettings.Get("CertificateLocation");
    String certificateStore = ConfigurationManager.AppSettings.Get("CertificateStore");
    string certificateSubject = ConfigurationManager.AppSettings.Get("CertificateSubject");
    String decryptedKey = string.Empty;
    try
    {
        X509Certificate2 encryptionCertificate = X509Utilities.GetCertificateBySubject(certificateSubject, certificateStore.ParseAsEnum&lt;StoreName&gt;(),
        certificateLocation.ParseAsEnum&lt;StoreLocation&gt;());
        if (encryptionCertificate == null )
            Helper.LogMessage(" Did not find Encryption Certificate on the sserver " );
        RSACryptoServiceProvider rsaProvider = (RSACryptoServiceProvider)encryptionCertificate.PrivateKey;
        byte[] cipherbytes = Convert.FromBase64String(dataToDecrypt);
        byte[] plainbytes = rsaProvider.Decrypt(cipherbytes, false);
        System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
        decryptedKey =  enc.GetString(plainbytes);
    }
  
    catch (Exception e)
    {
        Helper.LogMessage(e.Message + " Key Parsing error. DataToDecrypt = " + dataToDecrypt);
        throw e;
    }
    return decryptedKey;
  </code></pre>
  
  <blockquote>
    <p>&lt;CipherData>&lt;CipherValue>HQrhmJpbd0p32QjOFrOKQhNSr4q6bcbg+9AhxJS6yZR19Nqh3VDMwOW2wsCBuSmFlv7WjR7TzW6URjINvNbv2nMfsKu3M9dscxhmGY+jVtUJ6sTf7FHdK9D76miAdq1EIsm0lNtdW5etMx/85iMiFOObbyZuB8oaYeThToVjTUVYfNGQOJ99wvh8OL/40eomDlKfwN4eQ88kVbY1eUO1OxEfQsUbDWyXvZEvBPmYUb7km+C6rX8UjsLUrqOOpXym9oi5dH+T+kAP2Rb5N16VRxJHPGF/gXeuD+Jq4FSGtjiiBE9qvBIFWkt4hYabSgUE3Li5DqMoH/P9/EGqf6mpyvHjv8yJYRTpA//5nM43z/KCUFX8VrFCXBp0N1Y40zpZWJW2y9fSIlyGyMas1ByBlkxpRgjqqnv1L+pZohYmKQsOILhM34TASzddYgeQbPfoAuC8i/4cMWYDrO+NP+n5d97FZDPs3u3gMWefhWoSt0BSEwUCbaNmS9I39ihFwyT/6rmurgLvfY0AaFz16Q3qQlH3yVdGR2j+A2spfJLyMrRcVTSff6HKa6LC7xUO9aBF2WpEw1mxI0QXMY2VMtSwdT4pzMc+itbDe9r4ZW9BZhA7qsBd0oOVRxxxNvOo9eIUlLyGRzvMbX+oOUiHkAm/oil7Vll5JzvlzVrc4dzzOUA=&lt;/CipherValue>&lt;/CipherData></p>
  </blockquote>