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:
AsymmetricKeyParameter pubKey = (AsymmetricKeyParameter)pubReader.ReadObject();
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:
AsymmetricKeyParameter pubKey = (AsymmetricKeyParameter)pubReader.readPemObject();
However… this is when I hit the big problem, as I cannot cast from PemObject to AsymmetricKeyParameter and end up having an error…
here’s the majority of the code in question:
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));`
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
Regards,
Gonçalo Vieira
Try replacing
with