-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommunication.java
More file actions
116 lines (84 loc) · 2.21 KB
/
Communication.java
File metadata and controls
116 lines (84 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import java.io.*;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.util.Scanner;
public class Communication
{
Server serverClass;
Client clientClass;
Scanner input;
Scanner input2;
public Communication(){
serverClass = new Server();
clientClass = new Client();
input = new Scanner(System.in);
input2 = new Scanner(System.in);
}
public static void main(String[] args) {
Communication instance = new Communication();
instance.start();
}
public void start()
{
//menu
System.out.println("Going to Generate Keys");
serverClass.genKey(); // makes RSA Key
clientClass.genSessionKey(); // makes Session key
clientClass.encSessionKey(); // Encrypts Session key from Client
serverClass.decSessionKey(); // Server Decrypts session key
menu();
}
public void menu(){
int option = mainMenu();
while (option != 0) {
switch (option) {
case 1:
serverMessage();
break;
case 2:
clientMessage();
break;
case 3:
break;
}
option = mainMenu();
}
System.out.println("Exiting... bye");
}
/**
* mainMenu() - This method displays the menu for the application, reads the
* menu option that the user entered and returns it.
*
* @return the users menu choice
*/
private int mainMenu() {
System.out.println("=================");
System.out.println(" Select Option ");
System.out.println("=================");
System.out.println("1) Server sends Message to Client");
System.out.println("2) Client sends message to Server");
System.out.println("0) Exit");
System.out.print("==>>");
int option = input.nextInt();
return option;
}
public void serverMessage(){
System.out.println("Server Message > ");
System.out.print("> ");
String message = input2.nextLine();
System.out.println("Server > ");
serverClass.encryptMsg(message);
System.out.println("Client > ");
clientClass.decryptMsg();
}
public void clientMessage(){
System.out.println("Client Message > ");
System.out.print("> ");
String message = input2.nextLine();
System.out.println("Client > ");
clientClass.encryptMsg(message);
System.out.println("Server > ");
serverClass.decryptMsg();
}
}