How to send client's public key to server
Posted on 1998-11-12
The client and server are in 2 different machine. Given the client public key (PublicKey pubC), how do i send pubC to the server and the server received it in the PublicKey format.
Below is an example i found in some some books. It changes the public key to byte form and send it to the server. The server received it as bytes. However i do not know how the get it back to PublicKey form for encryption purposes.
DataOutputStream out = new DataOutputStream(s.getOutputStream());
byte keyBytes = pubC.getEncode();
DataInputStream in = new DataInputStream(s.getInputStream());
byte keyBytes = new byte[in.readInt()];
Below is another method i had tried, but i believed it will only work if the client and the server are in the same machine.
FileOutputStream ostream = new FileOutputStream("t.tmp");
ObjectOutputStream out = new ObjectOutputStream(ostream);
FileInputStream istream = new FileInputStream("t.tmp");
ObjectInputStream in = new ObjectInputStream(istream);
PublicKey pubC = (PublicKey)in.readObject();
Other things to take note are
1. I'm using JDK1.2beta3 with Cryptix-java V3.0.3
2. The public key is generated by Cryptix-java V3.0.3 using RSA algorthim
BaseRSAKeyPairGenerator kpgC = new BaseRSAKeyPairGenerator();
kpgC.initialize(64, new SecureRandom());
KeyPair pairC = kpgC.generateKeyPair();
pubC = pairC.getPublic();
privC = pairC.getPrivate();
3. The client and server are in different machines