/*
* @author blueShard
* @version 1.12.0
*
* Some @since versions may be not correct, because the @since tag got added in
* version 1.12.0 and I don't have all versions (1.0.0 - 1.11.0), so I cannot see when some methods were added
*/
package org.blueshard.cryptogx;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.swing.*;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
/**
*
Main class
* * @since 1.0.0 */ public class Main extends Application { protected static final int NON_PORTABLE = 1; protected static final int PORTABLE = 0; protected static final int TYPE = NON_PORTABLE; protected final static String configDefaultTextKey = ""; protected final static String configDefaultTextSalt = ""; protected final static String configDefaultTextAlgorithm = "AES-128"; protected final static String configDefaultFileEnDecryptKey = ""; protected final static String configDefaultFileEnDecryptSalt = ""; protected final static String configDefaultFileEnDecryptAlgorithm = "AES-128"; protected final static int configDefaultFileDeleteIterations = 5; protected final static String configDefaultFileOutputPath = ""; protected final static boolean configDefaultRemoveFileFromFileBox = false; protected final static boolean configDefaultLimitNumberOfThreads = true; private final static byte[] buffer = new byte[64]; private static Stage mainStage; private double rootWindowX, rootWindowY; protected static File config; protected static boolean isConfig; /** *Start the GUI
* * @param primaryStage of the GUI * @throws IOException if issues with loading 'mainGUI.fxml' * * @since 1.0.0 */ @Override public void start(Stage primaryStage) throws IOException { Thread.setDefaultUncaughtExceptionHandler(Main::exceptionAlert); mainStage = primaryStage; Parent root = FXMLLoader.load(getClass().getResource("resources/mainGUI.fxml")); primaryStage.initStyle(StageStyle.UNDECORATED); primaryStage.setResizable(false); primaryStage.setTitle("cryptoGX"); primaryStage.getIcons().add(new Image(getClass().getResource("resources/cryptoGX.png").toExternalForm())); Scene scene = new Scene(root); //Scene scene = new Scene(root, 900, 470); scene.setOnMouseDragged(event -> { primaryStage.setX(event.getScreenX() + rootWindowX); primaryStage.setY(event.getScreenY() + rootWindowY); }); scene.setOnMousePressed(event -> { rootWindowX = scene.getX() - event.getSceneX(); rootWindowY = scene.getY() - event.getSceneY(); }); primaryStage.setScene(scene); primaryStage.show(); } /** *Enter method for the application. * Can also be used to en- / decrypt text and files or secure delete files without starting GUI
* * @param args from the command line * @return * @throws BadPaddingException * @throws NoSuchAlgorithmException if wrong algorithm is given (command line) * @throws IllegalBlockSizeException if wrong size for key is given (command line) * @throws NoSuchPaddingException * @throws InvalidKeyException if invalid key is given (command line) * @throws InvalidKeySpecException * @throws IOException if files cannot be en- / decrypted or deleted correctly (command line) * @throws InvalidAlgorithmParameterException if wrong algorithm parameters are given (command line) * * @since 1.0.0 */ public static void main(String[] args) throws BadPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidKeyException, InvalidKeySpecException, IOException, InvalidAlgorithmParameterException { if (Main.TYPE == Main.PORTABLE) { String system = System.getProperty("os.name").toLowerCase(); if (system.startsWith("windows")) { config = new File("C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\cryptoGX\\cryptoGX.config"); File directory = new File("C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\cryptoGX"); if (!directory.isDirectory()) { directory.mkdir(); } } else if (system.startsWith("linux")) { config = new File(System.getProperty("user.home") + "/.cryptoGX/cryptoGX.config"); File directory = new File(System.getProperty("user.home") + "/.cryptoGX/"); if (!directory.isDirectory()) { directory.mkdir(); } } else { config = new File("cryptoGX.config"); } } else { config = new File("cryptoGX.config"); } isConfig = config.isFile(); if (args.length == 0) { launch(args); } else { args[0] = args[0].replace("-", ""); if (args[0].toLowerCase().equals("help") || args[0].toUpperCase().equals("H")) { System.out.println("Usage AES: \n\n" + " Text en- / decryption\n" + " encrypt:"Catch" all uncatched exceptions and opens an alert window
* * @param thread which called this method * @param throwable of the thread which called the method * * @since 1.3.0 */ private static void exceptionAlert(Thread thread, Throwable throwable) { throwable.printStackTrace(); AtomicReferenceShows an error alert window
* * @param message which will the alert show * @param error which will show after the message */ protected static void errorAlert(String message, String error) { AtomicReferenceShows an warning alert window
* * @param message that the alert window will show * * @since 1.4.0 */ protected static void warningAlert(String message) { AtomicReference