Solved

How to send client's public key to server

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

696 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