Fix message sending
This commit is contained in:
@@ -49,9 +49,9 @@ public class Main {
|
||||
System.out.println("Received message: " + text);
|
||||
|
||||
//Encrypting the message
|
||||
String encryptedMessage = encrypt(key, text);
|
||||
String base64Message = Base64.getEncoder().encodeToString(encryptedMessage.getBytes());
|
||||
System.out.println("Encrypted message to send : " + encryptedMessage);
|
||||
byte[] encryptedMessage = encrypt(key, text);
|
||||
String base64Message = Base64.getEncoder().encodeToString(encryptedMessage);
|
||||
System.out.println("Encrypted message to send : " + base64Message);
|
||||
|
||||
//Sending encrypted message
|
||||
send(socket, base64Message);
|
||||
@@ -83,13 +83,12 @@ public class Main {
|
||||
return keyGen.generateKey();
|
||||
}
|
||||
|
||||
public static String encrypt(SecretKey key, String message) throws Exception {
|
||||
public static byte[] encrypt(SecretKey key, String message) throws Exception {
|
||||
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, key);
|
||||
|
||||
byte[] ciphertext = cipher.doFinal(message.getBytes());
|
||||
return cipher.doFinal(message.getBytes());
|
||||
|
||||
return Base64.getEncoder().encodeToString(ciphertext);
|
||||
}
|
||||
|
||||
public static String decrypt(byte[] keyBytes, String base64IvAndCiphertext) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user