Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Transfering a public key over a socket: InvalidKeySpecException

843811Jul 3 2006 — edited Jul 4 2006
I'm tryring to transfer a clienside generated DSA publickey over a socket using base64 encoding. The server has to re-create the publicKey object using the transferred keystring.

When re-creating the PublicKey at serverside, i get an InvalidKeySpecException:
java.security.spec.InvalidKeySpecException: Inappropriate key specification: IOException: DerInputStream.getLength(): lengthTag=109, too big.

Client code:
				
// send as base64
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(publicKey);
byte [] publicKeyBytes = baos.toByteArray();
Base64Coder base64 = new Base64Coder();
char [] publicKeyChars = base64.encode(publicKeyBytes);

String publicKeyString = new String(publicKeyChars);

// send publicKey
os.write(publicKeyString.getBytes());
os.write('\n');
os.flush();
Server code:
String publicKeyString = readLine(is, false);
char [] publicKeyChars = publicKeyString.toCharArray();
Base64Coder base64 = new Base64Coder();
byte [] publicKeyBytes = base64.decode(publicKeyChars);
PublicKey publicKeyOther = KeyFactory.getInstance("DSA").generatePublic(new X509EncodedKeySpec(publicKeyBytes));
I'm quite new to Java and cryptography and maybe doing something stupid. Can anybody help me out?? Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 1 2006
Added on Jul 3 2006
6 comments
928 views