title: BouncyCastle Decryption works, but not Encryption?
body: <p>I'm getting an encrypted string from an external service that I need to decrypt, and then re-encrypt using the <a href="http://www.bouncycastle.org/csharp/" rel="nofollow noreferrer">BouncyCastle API</a>.</p>
  
  <p>I've managed to get decryption working fine, but encryption doesn't seem to work. When I try to decrypt a string generated by my encryption method I get an <code>InvalidCipherTextException</code> with the message "unknown block type".</p>
  
  <p>This is my decryption code, which successfully decrypts text from the service I'm interfacing with:</p>
  
  <pre><code>string Decrypt(string value) 
  {
      string Signature = "My_Signature";
      RsaKeyParameters keyParams = (RsaKeyParameters)PublicKeyFactory.CreateKey(Convert.FromBase64String(Signature));
      IBufferedCipher cipher = CipherUtilities.GetCipher("RSA/NONE/PKCS1Padding");
      cipher.Init(false, keyParams);
  
      byte[] secretBytes = Convert.FromBase64String(value);
      byte[] decrypted = cipher.DoFinal(secretBytes);
  
      return Encoding.Default.GetString(decrypted);
  }
  </code></pre>
  
  <p>This is my encryption method, which doesn't seem to generate an encrypted string that my decrypt method can handle:</p>
  
  <pre><code>string Encrypt(string value)
  {
      string Signature = "My_Signature";
      RsaKeyParameters keyParams = (RsaKeyParameters)PublicKeyFactory.CreateKey(Convert.FromBase64String(Signature));
      IBufferedCipher cipher = CipherUtilities.GetCipher("RSA/NONE/PKCS1Padding");
      cipher.Init(true, keyParams);
  
      byte[] secretBytes = Encoding.Default.GetBytes(value);
      byte[] encrypted = cipher.DoFinal(secretBytes);
  
      return Convert.ToBase64String(encrypted);
  }
  </code></pre>
  
  <p>I'm not really sure what I'm missing to make this work. Is there anything obvious I seem to be missing here?</p>