Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Problem in transporting Key

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Problem in transporting Key

    I am coding a program to transmit public key from a client to server.
    // 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();
    }
    }
    // 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
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Problem in transporting Key

    There's no method called write in DataOutputStream that writes out the type Key. Unfortunately, Java doesn't let you use pointers so you can't pass the byte values one-by-one through the output stream. Java's website has this alternative for sending encrypted messages and the public key: Lesson 3: Cryptography

Tags for this Thread