title: RSA Reverse Encryption using Certificate
body: <p>I am using certificate to encrypt my communication between WCF and Android. Encrypting using Public Key, and decrypting with Private Key is working fine. But I return a session ID from the WCF Application to the Android Client. Now, I need to encrypt the SessionID using my Private Key and Encrypt at the client side using Public Key (Reverse). This reverse encryption and decryption is working fine in the Android Test. But in my C# Test, decryption shows error "Key doesn't exist". I tried changing the encoding to all the possible ones, but no hope. Here is the code.</p>
  
  <pre><code>    private void Encrypt()
      {
  
          X509Certificate2 myCert2 = null;
          myCert2 = new X509Certificate2(Resource1.code, "code");
          RSACryptoServiceProvider RSA = (RSACryptoServiceProvider)myCert2.PrivateKey;
  
          string strtt = "This is a test"; 
          byte[] ascenc = Encoding.UTF32.GetBytes(strtt);
          encrbyte = RSA.Encrypt(ascenc, false);
          encrypted_string =Convert.ToBase64String(encrbyte);
          textBox2.Text = encrypted_string;
  
  
      }
  
      private void Decrypt()
      {
  
          var myCert2 = new X509Certificate2(Resource1.code, "code");
          RSACryptoServiceProvider RSA = (RSACryptoServiceProvider)myCert2.PublicKey.Key;
          byte[] ascby = Convert.FromBase64String(encrypted_string);
          byte[] decrypted_byte = RSA.Decrypt(ascby, false);
          string decrypted_text = Encoding.UTF32.GetString(decrypted_byte);
          textBox3.Text = decrypted_text; 
  
      }
  </code></pre>