Solved

How to send client's public key to server

Posted on 1998-11-12
3
539 Views
Last Modified: 2008-03-10
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.

client:
      DataOutputStream out = new DataOutputStream(s.getOutputStream());
      byte[] keyBytes = pubC.getEncode();
      out.writeInt(keyBytes.length);
      out.write(keyBytes);
      out.close();

server:
      DataInputStream in = new DataInputStream(s.getInputStream());
      byte[] keyBytes = new byte[in.readInt()];
      in.readFully(keyBytes);
      out.close();


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.

client:
      FileOutputStream ostream = new FileOutputStream("t.tmp");
      ObjectOutputStream out = new ObjectOutputStream(ostream);
      out.writeObject(pubC);
      ostream.close();

server:
      FileInputStream istream = new FileInputStream("t.tmp");
      ObjectInputStream in = new ObjectInputStream(istream);
      PublicKey pubC = (PublicKey)in.readObject();
      istream.close();


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
0
Comment
Question by:ksmak
  • 2
3 Comments
 
LVL 4

Expert Comment

by:evijay
ID: 1227393
Is the public key serializable?. In that case, use object serialization and serialize it to stream of bytes and write it to output stream. then on the other end deserialize it.


0
 

Author Comment

by:ksmak
ID: 1227394
Thanks for the help, I've got your hint.
0
 
LVL 4

Accepted Solution

by:
evijay earned 40 total points
ID: 1227395
In that case, use object serialization and serialize it to stream of
bytes and write it to output stream. then on the other end deserialize
it.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ForLoop Example 3 48
servlet web applications   metadata-complete="true" or false 3 40
hibernate jars 4 30
How to determine if a string is a valid SHA value 7 32
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question