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.