Solved

How to send client's public key to server

Posted on 1998-11-12
3
536 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now