title: J2ME, Exception when casting from PemObject to AsymmetricKeyParameter with BouncyCastle
body: <p>my question for today is about the BouncyCastle encryption Library for J2ME,
  I have some code in C# in which I do the following cast:</p>
  
  <p><code>AsymmetricKeyParameter pubKey = (AsymmetricKeyParameter)pubReader.ReadObject();</code></p>
  
  <p>this works on the C# end, however when I do it in Java I get an error stating that pubReader doesn't have a ReadObject() method, I changed it to readObject(), still doesn't exist so I went ahead to search for a method that would return an Object type, I only found readPemObject() as follows:</p>
  
  <p><code>AsymmetricKeyParameter pubKey = (AsymmetricKeyParameter)pubReader.readPemObject();</code></p>
  
  <p>However... this is when I hit the big problem, as I cannot cast from PemObject to AsymmetricKeyParameter and end up having an error...</p>
  
  <p>here's the majority of the code in question:</p>
  
  <pre><code>PemReader pubReader = new PemReader(new StringReader(pubKey));      
  AsymmetricKeyParameter nhe = (AsymmetricKeyParameter)pubReader.readPemObject();
  
  Imported teste = new Imported();        
  PemObject pobj = pubReader.readPemObject();
  
  System.out.println("PemObject: " + pobj);
  byte[] output = teste.Encrypt(holyshizzle.getBytes(), nhe);
  System.out.println(new String(output));         
  byte[] revvit = teste.Decrypt(output, (AsymmetricKeyParameter)blah.getPrivate());
  System.out.println(new String(revvit));`
  </code></pre>
  
  <p>PS: The Imported class is where the encrypt/decrypt code is and all of that is working fine (tested it with generated keys), I'm attempting to do this with pre-made encryption keys</p>
  
  <p>Regards,
  Gonçalo Vieira</p>