Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to send client's public key to server

Posted on 1998-11-12
3
Medium Priority
?
549 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 160 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

610 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