For client and server communication By using Diffe and Helman algorithm(DH) generate a secret session key(k) from both sides (from client and server separately) by using Java .and also by accepting some message from client by using the generated secret session key (K) encrypt the message from client-side and send to server and server uses the generated secret session key(k) of his own and decrypt the received encrypted message in java. thanks in advance.
code
solution
//output
//copyable code
//serverside.java
import java.net.*;
import java.io.*;
public class serverside {
public static void main(String[] args) throws IOException
{
try {
int portnumber = 8088;
// set Key
int b1 = 3;
// declare the variable
double cl_P, cl_G, cl_A, B, B_DASH;
String B_string;
// Connection
ServerSocket server = new ServerSocket(portnumber);
System.out.println("wait client portnumber " + server.getLocalPort() + "...");
Socket s1 = server.accept();
System.out.println("connected to " + s1.getRemoteSocketAddress());
// Private Key
System.out.println("Server side: Private Key = " + b1);
// Accepts data
DataInputStream in1 = new DataInputStream(s1.getInputStream());
cl_P = Integer.parseInt(in1.readUTF());
System.out.println("Client side: P = " + cl_P);
cl_G = Integer.parseInt(in1.readUTF());
System.out.println("Client side: G = " + cl_G);
cl_A = Double.parseDouble(in1.readUTF());
System.out.println("Client side : Public Key = " + cl_A);
B = ((Math.pow(cl_G, b1)) % cl_P);
B_string = Double.toString(B);
OutputStream os = s1.getOutputStream();
DataOutputStream out1 = new DataOutputStream(os);
out1.writeUTF(B_string);
B_DASH = ((Math.pow(cl_A, b1)) % cl_P);
System.out.println("Symmetric Encryption secret key= "
+ B_DASH);
s1.close();
}
catch (SocketTimeoutException s) {
System.out.println("timed out!");
}
catch (IOException e) {
}
}
}
//clientside.java
import java.net.*;
import java.io.*;
public class clientside {
public static void main(String[] args)
{
try {
String p_string, g_string, A_string;
String Name = "localhost";
int portnumber = 8088;
// Declare variable
int p1 = 23;
int g1 = 9;
int a1 = 4;
double A_dash, server_B;
// connection
System.out.println("Connecting to " + Name
+ " on portnumber " + portnumber);
Socket cl = new Socket(Name, portnumber);
System.out.println("connected to "
+ cl.getRemoteSocketAddress());
// Sends DATA
OutputStream OS = cl.getOutputStream();
DataOutputStream out = new DataOutputStream(OS);
p_string = Integer.toString(p1);
out.writeUTF(p_string);
g_string = Integer.toString(g1);
out.writeUTF(g_string);
double A1 = ((Math.pow(g1, a1)) % p1);
A_string = Double.toString(A1);
out.writeUTF(A_string);
// KEY
System.out.println("Client Side: Private Key = " + a1);
// Accepts the data
DataInputStream in1 = new DataInputStream(cl.getInputStream());
server_B = Double.parseDouble(in1.readUTF());
System.out.println("Server side : Public Key = " + server_B);
A_dash = ((Math.pow(server_B, a1)) % p1);
System.out.println("Symmetric Encryption for secret key= "
+ A_dash);
cl.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
For client and server communication By using Diffe and Helman algorithm(DH) generate a secret session key(k)...
In Java write a code that performs DH(Diffe and Helman) algorithm for client and server Key generation.
The Diffie-Hellman public-key encryption algorithm is an alternative key exchange algorithm that is used by protocols such as IPSec for communicating parties to agree on a shared key. The DH algorithm makes use of a large prime number p and another large number, g that is less than p. Both p and g are made public (so that an attacker would know them). In DH, Alice and Bob each independently choose secret keys, ?? and ??, respectively. Alice then computes...
Exercise 3.2 (Symmetric and Asymmetric Encryption) t In this exercise, you will send an encrypted message from a socket client to a socket server. The message will be encrypted using AES symmetric encryption algorithm in the client. The server receives this ciphertext and decrypt it using the same symmetric key. Before communication over symmetric encryption, you need to first securely distribute the symmetric key between sender and receiver. You can use asymmetric encryption to help distribute the symmetric key. The...
Suppose that Alice wants to initiate a message exchange (also called session) to instruct her bank, NetBank, to pay Bob N40. Alice shares a long-term secret, X, with NetBank (hereafter denoted as C). Alice starts the session by sending a service request, (A, C, n), to NetBank, 3. a. where A is Alice's identity, C is NetBank's identity, and n is a nonce. Assume that NetBank keeps a record of the nonces used by Alice for X. Answer the following...
I have to modify a server program and chat program to work as the following instructions but I am completely clueless as to where to start. I'd appreciate any help on how to atleast get started. This must be done in java. Diffie-Hellman Two parties use a key agreement protocol to generate identical secret keys for encryption without ever having to transmit the secret key. The protocol works by both parties agreeing on a set of values (a) and (q)....
Cryptography, the study of secret writing, has been around for a very long time, from simplistic techniques to sophisticated mathematical techniques. No matter what the form however, there are some underlying things that must be done – encrypt the message and decrypt the encoded message. One of the earliest and simplest methods ever used to encrypt and decrypt messages is called the Caesar cipher method, used by Julius Caesar during the Gallic war. According to this method, letters of the...
Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA { private BigInteger phi; private BigInteger e; private BigInteger d; private BigInteger num; public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Enter the message you would like to encode, using any ASCII characters: "); String input = keyboard.nextLine(); int[] ASCIIvalues = new int[input.length()]; for (int i = 0; i < input.length(); i++) { ASCIIvalues[i] = input.charAt(i); } String ASCIInumbers...
JAVA Problem: With the recent news about data breaches and different organizations having their clients’ information being exposed, it is becoming more and more important to find ways to protect our sensitive data. In this program we will develop a simple tool that helps users generate strong passwords, encrypt and decrypt data using some cyphering techniques. You will need to create two classes. The first class is your driver for the application and contains the main method. Name this class...