JAVA   24

DH Client

Guest on 14th August 2022 06:41:09 AM

  1. // Sample use of Java classes MessageDigest and SecureRandom.  See the Java
  2. // API for more information.  Recall, MessageDigest supplies hash objects and
  3. // SecureRandom supplies a crytographically strong random number (a large
  4. // number with a high probability of being prime).
  5. import java.io.*;
  6. import java.net.*;            // For Socket, etc.
  7. import java.math.*;           // For BigInteger
  8.  
  9. public class DH_Client {
  10.    public static void main (String arg[]) {
  11.       InputStreamReader isr;
  12.       BufferedReader in;
  13.       PrintWriter out;
  14.  
  15.       try {
  16.          DiffieHellmanExchange dh = new DiffieHellmanExchange("DHKey");
  17.  
  18.          // Connect to the server
  19.          Socket connect = new Socket("localhost", 8284);
  20.          isr = new InputStreamReader(connect.getInputStream());
  21.          in = new BufferedReader(isr);
  22.          out = new PrintWriter(connect.getOutputStream(), true);
  23.  
  24.          dh.computeSecret(in,out);
  25.  
  26.          System.out.println("Client: secret = "+dh.s_secret);
  27.       } catch (Exception e) {
  28.          System.out.println("Yikes!");
  29.       }
  30.    }
  31. }

Raw Paste


Login or Register to edit or fork this paste. It's free.