Java RSA encryption problems

Status
Not open for further replies.

Major Major

Ars Scholae Palatinae
755
Subscriptor
Hey all,

I'm having some serious problems with RSA crypto in java. The program I am writing needs to encrypt information using RSA to send to a server. Each side of the connection is a java app btw. I am generating keypairs before hand and including them in data files along with each part of the app. I can't seem to get the server side app to build a PrivateKey object from the data in my private key file. I've tried a bunch of different ways of doing it (X509 encoding of the key in the file, serialized Key object in the file, and serialized modulus and exponent numbers of the key in a file) and nothing is working for me. I'm not even sure if its a problem with my code or just the JCE implementation I'm using. This is for a school project and they're forcing us to use JDK1.3.1 and the cryptix.org JCE implementation.

Any help would be greatly appreciated. I've run into a wall on this one. Spent a good six hours last night fighting this bug and I've plain run out of ideas.
 

Major Major

Ars Scholae Palatinae
755
Subscriptor
Nevermind, I figured it out. For the record, and the benefit of anyone else who might run into this in the future, here's the fix.

Apparently what little documentation there is for this kind of stuff doesn't mention the fact that using the getEncoded() method of PublicKey and PrivateKey objects results in different types of encoding for each. PublicKey results in an X.509 encoding style and PrivateKey uses RSA PKCS#8 style. So when reading them in you have to use the appropriate [X509|PKCS8]EncodedKeySpec object type.

It's pretty sad when the only source of accurate documentation for a widely used programming language is trawling newsgroups. Especially so when its for security libraries....
 
Status
Not open for further replies.