public static void main(String args[]) { // Takes input from user and stores in inputkey Scanner in1 = new Scanner(System.in); String inputKey = in1.nextLine(); // Takes 2nd input from user and stores in inputPlainText Scanner in2 = new Scanner(System.in); String plainText = in2.nextLine(); // If condition makes sure that user has entered exactly 32 hexadecimal digits if (!inputKey.isEmpty() || !plainText.isEmpty()) { if ((inputKey.matches("[0-9A-F]{32}")) && (plainText.matches("[0-9A-F]{32}"))) { // cText stores the ciphertext AEScipher kg = new AEScipher(); String cText = kg.aes(plainText, inputKey); // Print the ciphertext System.out.print(cText); } else { // If user input is incorrect, terminate the program System.out.println("Invalid input key or plaintext, exiting....."); } } else { System.out.println("Problem in input"); } }
public byte[] readBytes(int playerId) { try { InputStream in = cm.getInputStream(playerId); DataInputStream dis = new DataInputStream(in); int len = dis.readInt(); byte[] data = new byte[len]; if (len > 0) { dis.readFully(data); } return aesCipher.decrypt(data); } catch (IOException e) { e.printStackTrace(); return null; } }
public void sendMessage(String msgToSend, int playerId) { sendInsecuredBytes(aesCipher.encrypt(msgToSend.getBytes()), playerId); }
public void sendBytes(byte[] myByteArray, int playerId) { byte[] encrypted = aesCipher.encrypt(myByteArray); sendBytes(encrypted, 0, encrypted.length, playerId); }
public String receiveMessage(int id) { return new String(aesCipher.decrypt(readInsecuredBytes(id))); }