* fixing security issues by encryption
Signed-off-by: CubeBit <denis-seredenko@ukr.net>
This commit is contained in:
@@ -16,6 +16,7 @@ import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
@@ -88,12 +89,12 @@ public class ChatController {
|
||||
sendMsgBtn.setDisable(true);
|
||||
}
|
||||
|
||||
public void sendMessage() throws IllegalBlockSizeException, NoSuchPaddingException, BadPaddingException, NoSuchAlgorithmException, InvalidKeyException {
|
||||
public void sendMessage() throws IllegalBlockSizeException, NoSuchPaddingException, BadPaddingException, NoSuchAlgorithmException, InvalidKeyException, InvalidAlgorithmParameterException {
|
||||
if (!clientThread.aesReceived && !clientThread.rsaReceived)
|
||||
System.out.println("Wait for complete initialisation!");
|
||||
|
||||
if (clientThread.rsaReceived && clientThread.aesReceived) {
|
||||
String encryptedText = EncryptionUtil.encryptWithAES(messageTextInput.getText(), aesKey);
|
||||
String encryptedText = EncryptionUtil.encryptWithAES(messageTextInput.getText(), aesKey, Main.ivKey);
|
||||
clientThread.out.println("TXT" + encryptedText);
|
||||
clientThread.out.flush();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
@@ -65,8 +66,14 @@ public class ClientThread implements Runnable {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prefix.equals("IVK")) {
|
||||
String decryptedIVKey = EncryptionUtil.decryptWithRSA(restMessage, Main.keys.getPrivate());
|
||||
Main.ivKey = EncryptionUtil.ivKeyFromString(decryptedIVKey);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prefix.equals("TXT") && aesReceived && rsaReceived) {
|
||||
String decryptedMessage = EncryptionUtil.decryptWithAES(restMessage, Main.aesKey);
|
||||
String decryptedMessage = EncryptionUtil.decryptWithAES(restMessage, Main.aesKey, Main.ivKey);
|
||||
|
||||
Label text = new Label(decryptedMessage);
|
||||
text.setFont(new Font(14));
|
||||
@@ -75,7 +82,7 @@ public class ClientThread implements Runnable {
|
||||
Platform.runLater(() -> messagesBox.getChildren().add(text));
|
||||
}
|
||||
} catch (NoSuchPaddingException | IllegalBlockSizeException | IOException | NoSuchAlgorithmException |
|
||||
InvalidKeySpecException | BadPaddingException |InvalidKeyException e) {
|
||||
InvalidKeySpecException | BadPaddingException |InvalidKeyException | InvalidAlgorithmParameterException e) {
|
||||
System.err.println("Disconnected from server!");
|
||||
System.exit(-1);
|
||||
closeAllConnections(clientSocket, in, out);
|
||||
|
||||
@@ -24,6 +24,8 @@ public class Main extends Application {
|
||||
|
||||
static SecretKey aesKey;
|
||||
|
||||
static byte[] ivKey;
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws IOException, NoSuchAlgorithmException {
|
||||
keys = EncryptionUtil.generateRSAKeys();
|
||||
|
||||
Reference in New Issue
Block a user