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(); } }I got the following error:// 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(); } }
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