Posted by abc_tom
on June 14, 2008 at 12:05 AM PDT
We have to build a J2ME application which would encrypt data and send it via a https request to a web application on a web server. The web application would decrypt and do the necessary processing.
Similarly, when the web server returns back the response, it would send the data in encrypted format to the midlet, again on the midlet, there should be some decryption to be done.
With some help from a guy at one of the forums, I could try to generate public - private key pair using keytoo, extract the public and private keys seperately to individual files. I was also able to read the public key on a J2ME midlet and encrypt the data successfully. However, when I was trying to decrypt the data using a private key which I am reading from a file and trying to use the private key using the following line of code -
PrivateKey privateKey = keyFactory.generatePrivate(privateKeySpec);
It throws an error stating InvalidKeySpecException
Any thoughts/suggestions on this, please do let me know
Secondly, This particular method keyFactory.generatePrivate is available as part of J2SE but is not avaialble in the java.security.KeyFactory of J2ME. That gives rise to another bottleneck for me when I need to decrypt the data sent by the web application in encrypted form. Is there any other way to use the private key which exists in file.
I have explained my problem at this thread in detail along with source code..