Results 1 to 4 of 4
  1. #1
    ttsdinesh is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Question Problem in transporting Key

    I am coding a program to transmit public key from a client to server.
    Java Code:
    // SERVER
    import java.security.Key;
    import java.security.KeyPair;
    import java.security.KeyPairGenerator;
    import java.security.SecureRandom;
    import java.security.Security;
    import javax.crypto.Cipher;
    import java.io.*;
    import java.net.*;
    class server
    {
    public static void main(String a[])throws Exception
    {
        Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
        Cipher cipher = Cipher.getInstance("RSA/None/NoPadding", "BC");
        ServerSocket ss=new ServerSocket(4321);
        Socket s=ss.accept();
        BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));
        System.out.println(in.readLine());
        s.close();
        ss.close();
    }
    }
    Java Code:
    // CLIENT
    import java.security.Key;
    import java.security.KeyPair;
    import java.security.KeyPairGenerator;
    import java.security.SecureRandom;
    import java.security.Security;
    import javax.crypto.Cipher;
    import java.io.*;
    import java.net.*;
    class client
    {
    public static void main(String a[])throws Exception
    {
        Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
        Cipher cipher = Cipher.getInstance("RSA/None/NoPadding", "BC");
        SecureRandom random = new SecureRandom();
        KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", "BC");
        generator.initialize(512, random);
        KeyPair pair = generator.generateKeyPair();
        Key pubKey = pair.getPublic();
        Key privKey = pair.getPrivate();
        Socket s=new Socket("localhost",4321);
        DataOutputStream out=new DataOutputStream(s.getOutputStream());
        out.write(pubKey);
        s.close();
    }
    }
    I got the following error:
    C:\jdk1.6\bin>javac test4.java
    test4.java:28: cannot find symbol
    symbol : method write(java.security.Key)
    location: class java.io.DataOutputStream
    out.write(pubKey);
    ^
    1 error
    Please somebody help me

  2. #2
    Bill89 is offline Member
    Join Date
    Dec 2009
    Location
    Maine
    Posts
    11
    Rep Power
    0

    Default

    Think the problem is that there isn't a write() method that takes an Object of "Key", in the DataOutputStream class.

    So you need to convert it to something else, like a byte array maybe.

  3. #3
    ttsdinesh is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Question

    I tried
    Java Code:
    (byte)pubKey;
    and also
    Java Code:
    new String(pubKey);
    . But its shows only error.:confused:

  4. #4
    Bill89 is offline Member
    Join Date
    Dec 2009
    Location
    Maine
    Posts
    11
    Rep Power
    0

    Default

    Try:

    Java Code:
    out.write(pubKey.toString().getBytes());
    Last edited by Bill89; 12-06-2009 at 06:10 PM.

Similar Threads

  1. simple line problem / for loop problem
    By helpisontheway in forum New To Java
    Replies: 1
    Last Post: 11-17-2009, 07:12 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •