Our code ☭
This commit is contained in:
21
src/main/java/common/Logger.java
Normal file
21
src/main/java/common/Logger.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package common;
|
||||||
|
|
||||||
|
public class Logger {
|
||||||
|
public static void displayInfo(String message){
|
||||||
|
final String BLUE = "\u001B[34m";
|
||||||
|
final String RESET = "\u001B[0m";
|
||||||
|
System.out.println(BLUE + "Info >>> " + message + RESET);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void displayReceived(String message){
|
||||||
|
String GREEN = "\u001B[32m";
|
||||||
|
String RESET = "\u001B[0m";
|
||||||
|
System.out.println(GREEN + "Received >>> " + message + RESET);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void displaySent(String message){
|
||||||
|
final String RED = "\u001B[31m";
|
||||||
|
final String RESET = "\u001B[0m";
|
||||||
|
System.out.println(RED + "Sent >>> " + message + RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/main/java/common/SocketManager.java
Normal file
19
src/main/java/common/SocketManager.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package common;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public class SocketManager {
|
||||||
|
public static void send(Socket socket, String data) throws IOException {
|
||||||
|
OutputStream output = socket.getOutputStream();
|
||||||
|
output.write(String.format("%s\r\n", data).getBytes(StandardCharsets.UTF_8));
|
||||||
|
output.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String readResponse(BufferedReader reader) throws IOException {
|
||||||
|
return reader.readLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,11 @@ import java.security.NoSuchAlgorithmException;
|
|||||||
import java.security.NoSuchProviderException;
|
import java.security.NoSuchProviderException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
import static common.Logger.displayInfo;
|
||||||
|
import static common.Logger.displayReceived;
|
||||||
|
import static common.Logger.displaySent;
|
||||||
|
import static common.SocketManager.send;
|
||||||
|
import static common.SocketManager.readResponse;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
@@ -87,34 +92,6 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void displayInfo(String message){
|
|
||||||
final String BLUE = "\u001B[34m";
|
|
||||||
final String RESET = "\u001B[0m";
|
|
||||||
System.out.println(BLUE + "Info >>> " + message + RESET);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void displayReceived(String message){
|
|
||||||
String GREEN = "\u001B[32m";
|
|
||||||
String RESET = "\u001B[0m";
|
|
||||||
System.out.println(GREEN + "Received >>> " + message + RESET);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void displaySent(String message){
|
|
||||||
final String RED = "\u001B[31m";
|
|
||||||
final String RESET = "\u001B[0m";
|
|
||||||
System.out.println(RED + "Sent >>> " + message + RESET);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void send(Socket socket, String data) throws IOException {
|
|
||||||
OutputStream output = socket.getOutputStream();
|
|
||||||
output.write(String.format("%s\r\n", data).getBytes(StandardCharsets.UTF_8));
|
|
||||||
output.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String readResponse(BufferedReader reader) throws IOException {
|
|
||||||
return reader.readLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SecretKey get3DESKey() throws NoSuchAlgorithmException, NoSuchProviderException {
|
public static SecretKey get3DESKey() throws NoSuchAlgorithmException, NoSuchProviderException {
|
||||||
KeyGenerator keyGen = KeyGenerator.getInstance(ALGORITHM, PROVIDER);
|
KeyGenerator keyGen = KeyGenerator.getInstance(ALGORITHM, PROVIDER);
|
||||||
keyGen.init(new SecureRandom());
|
keyGen.init(new SecureRandom());
|
||||||
|
|||||||
Reference in New Issue
Block a user