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
Solved

How to send client's public key to server

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
spring jars download 1 35
maven module vs maven project 3 46
java mysql insert application 14 25
junit as external jar or library 7 22
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

790 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