From 63e7e3229ac26976c7a5fc08ff4cc27ebbfc8d56 Mon Sep 17 00:00:00 2001 From: Francesco Valentini Date: Sat, 11 Nov 2023 14:31:04 +0100 Subject: [PATCH] Cambiato il layout a GroupLayout e aggiornata la codifica delle chiavi pubbliche ECDH Passaggio dal layout fisso a GroupLayout, aggiornata la codifica delle chiavi pubbliche ECDH da Base64 a Base32-c --- .../TextEncryptionUtility/Ecdh.java | 10 +- .../Settings_Window.java | 222 +++++++++++++----- .../TextEncryptionUtil_Main.java | 94 ++++++-- 3 files changed, 248 insertions(+), 78 deletions(-) diff --git a/src/it/HackerInside/TextEncryptionUtility/Ecdh.java b/src/it/HackerInside/TextEncryptionUtility/Ecdh.java index a81ce65..b22b45e 100644 --- a/src/it/HackerInside/TextEncryptionUtility/Ecdh.java +++ b/src/it/HackerInside/TextEncryptionUtility/Ecdh.java @@ -9,9 +9,9 @@ import java.util.*; import java.nio.ByteBuffer; -import java.util.Base64; import javax.crypto.*; import javax.crypto.spec.SecretKeySpec; +import org.apache.commons.codec.binary.Base32; public class Ecdh { @@ -26,11 +26,15 @@ public Ecdh(int bitSize) throws NoSuchAlgorithmException { } public String getPublicKey() { - return Base64.getEncoder().encodeToString(ourPk); + Base32 base32 = new Base32(); + return base32.encodeAsString(ourPk).replace('=', '9'); } public byte[] generateSharedSecret(String otherPkBase64) throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException { - byte[] otherPk = Base64.getDecoder().decode(otherPkBase64); + Base32 base32 = new Base32(); + + otherPkBase64 = otherPkBase64.replace('9', '='); + byte[] otherPk = base32.decode(otherPkBase64); KeyFactory kf = KeyFactory.getInstance("EC"); X509EncodedKeySpec pkSpec = new X509EncodedKeySpec(otherPk); diff --git a/src/it/HackerInside/TextEncryptionUtility/Settings_Window.java b/src/it/HackerInside/TextEncryptionUtility/Settings_Window.java index 39ab16b..9a15f2a 100644 --- a/src/it/HackerInside/TextEncryptionUtility/Settings_Window.java +++ b/src/it/HackerInside/TextEncryptionUtility/Settings_Window.java @@ -46,6 +46,9 @@ import javax.swing.border.EtchedBorder; import javax.swing.event.PopupMenuListener; import javax.swing.event.PopupMenuEvent; +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; +import javax.swing.LayoutStyle.ComponentPlacement; public class Settings_Window { @@ -96,47 +99,34 @@ private void initialize() { JPanel panel = new JPanel(); panel.setBackground(Color.DARK_GRAY); tabbedPane.addTab("General", null, panel, null); - panel.setLayout(null); JCheckBox chckbLineWrapping = new JCheckBox("TextArea Wrapping"); chckbLineWrapping.setBackground(Color.WHITE); - chckbLineWrapping.setBounds(10, 124, 153, 23); - panel.add(chckbLineWrapping); JSpinner spinnerSpacing = new JSpinner(); spinnerSpacing.setBackground(Color.WHITE); spinnerSpacing.setModel(new SpinnerNumberModel(0, 0, 10, 1)); spinnerSpacing.setFont(new Font("Tahoma", Font.PLAIN, 14)); - spinnerSpacing.setBounds(93, 67, 51, 20); - panel.add(spinnerSpacing); JLabel lblSpacing = new JLabel("SPACING:"); lblSpacing.setForeground(Color.WHITE); lblSpacing.setFont(new Font("Tahoma", Font.PLAIN, 15)); - lblSpacing.setBounds(10, 70, 87, 14); - panel.add(lblSpacing); JLabel lblEncoding = new JLabel("ENCODING:"); lblEncoding.setForeground(Color.WHITE); lblEncoding.setFont(new Font("Tahoma", Font.PLAIN, 15)); - lblEncoding.setBounds(10, 22, 87, 14); - panel.add(lblEncoding); JComboBox cmbEncoding = new JComboBox(); cmbEncoding.setBackground(Color.WHITE); cmbEncoding.setToolTipText(""); cmbEncoding.setFont(new Font("Tahoma", Font.PLAIN, 15)); - cmbEncoding.setBounds(93, 11, 200, 36); - panel.add(cmbEncoding); cmbEncoding.setModel(new DefaultComboBoxModel(new String[] {"Base64", "Base58", "Hex", "PGP Word list", "Base36", "Base32", "Base32-C"})); JCheckBox chckbCompression = new JCheckBox("GZIP Compression"); chckbCompression.setBackground(Color.WHITE); - chckbCompression.setBounds(10, 94, 153, 23); - panel.add(chckbCompression); JButton btnSaveSettings = new JButton("SAVE"); btnSaveSettings.setBackground(Color.WHITE); @@ -146,8 +136,6 @@ public void actionPerformed(ActionEvent e) { } }); btnSaveSettings.setFont(new Font("Tahoma", Font.BOLD, 14)); - btnSaveSettings.setBounds(181, 158, 89, 36); - panel.add(btnSaveSettings); // Load prefs try { @@ -155,21 +143,70 @@ public void actionPerformed(ActionEvent e) { cmbEncoding.setSelectedIndex(prefs.getInt("encoding", 0)); spinnerSpacing.setValue(prefs.getInt("spacing", 0)); + GroupLayout gl_panel = new GroupLayout(panel); + gl_panel.setHorizontalGroup( + gl_panel.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel.createSequentialGroup() + .addGap(10) + .addGroup(gl_panel.createParallelGroup(Alignment.LEADING) + .addComponent(lblEncoding, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE) + .addGroup(gl_panel.createSequentialGroup() + .addGap(83) + .addComponent(cmbEncoding, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)))) + .addGroup(gl_panel.createSequentialGroup() + .addGap(10) + .addGroup(gl_panel.createParallelGroup(Alignment.LEADING) + .addComponent(lblSpacing, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE) + .addGroup(gl_panel.createSequentialGroup() + .addGap(83) + .addComponent(spinnerSpacing, GroupLayout.PREFERRED_SIZE, 51, GroupLayout.PREFERRED_SIZE)))) + .addGroup(gl_panel.createSequentialGroup() + .addGap(10) + .addComponent(chckbCompression, GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE) + .addGap(289)) + .addGroup(gl_panel.createSequentialGroup() + .addGap(10) + .addComponent(chckbLineWrapping, GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE) + .addGap(289)) + .addGroup(gl_panel.createSequentialGroup() + .addGap(181) + .addComponent(btnSaveSettings, GroupLayout.PREFERRED_SIZE, 89, GroupLayout.PREFERRED_SIZE)) + ); + gl_panel.setVerticalGroup( + gl_panel.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel.createSequentialGroup() + .addGap(11) + .addGroup(gl_panel.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel.createSequentialGroup() + .addGap(11) + .addComponent(lblEncoding, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)) + .addComponent(cmbEncoding, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)) + .addGap(20) + .addGroup(gl_panel.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel.createSequentialGroup() + .addGap(3) + .addComponent(lblSpacing, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)) + .addComponent(spinnerSpacing, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)) + .addGap(7) + .addComponent(chckbCompression) + .addGap(7) + .addComponent(chckbLineWrapping) + .addGap(11) + .addComponent(btnSaveSettings, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)) + ); + panel.setLayout(gl_panel); JPanel panel_1 = new JPanel(); panel_1.setBackground(Color.DARK_GRAY); tabbedPane.addTab("FILL", null, panel_1, null); - panel_1.setLayout(null); JPanel panel_2 = new JPanel(); panel_2.setLayout(null); panel_2.setForeground(Color.WHITE); panel_2.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "KEY", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(255, 255, 255))); panel_2.setBackground(Color.DARK_GRAY); - panel_2.setBounds(10, 11, 432, 116); - panel_1.add(panel_2); JTextArea txtbSecretKey = new JTextArea(); txtbSecretKey.setForeground(Color.WHITE); @@ -208,8 +245,6 @@ public void stateChanged(ChangeEvent e) { } } }); - chckbxChiaveEsterna.setBounds(183, 218, 154, 23); - panel_1.add(chckbxChiaveEsterna); JButton btnGeneraChiave = new JButton("RANDOM KEY"); btnGeneraChiave.setBackground(Color.WHITE); @@ -237,21 +272,15 @@ public void actionPerformed(ActionEvent e) { } } }); - btnGeneraChiave.setBounds(22, 218, 148, 35); - panel_1.add(btnGeneraChiave); JLabel lblAliasChiave = new JLabel("ALIAS:"); lblAliasChiave.setForeground(Color.WHITE); lblAliasChiave.setFont(new Font("Tahoma", Font.PLAIN, 14)); - lblAliasChiave.setBounds(10, 138, 102, 23); - panel_1.add(lblAliasChiave); txtbAliasChiave = new JTextField(); txtbAliasChiave.setBackground(Color.WHITE); txtbAliasChiave.setFont(new Font("Tahoma", Font.PLAIN, 14)); txtbAliasChiave.setColumns(10); - txtbAliasChiave.setBounds(112, 138, 330, 23); - panel_1.add(txtbAliasChiave); JButton btnImportaChiave = new JButton("FILL"); btnImportaChiave.setBackground(Color.WHITE); @@ -303,22 +332,16 @@ public void actionPerformed(ActionEvent e) { } }); - btnImportaChiave.setBounds(22, 264, 148, 35); - panel_1.add(btnImportaChiave); JLabel lblKcv = new JLabel("KCV:"); lblKcv.setForeground(Color.WHITE); lblKcv.setFont(new Font("Tahoma", Font.PLAIN, 14)); - lblKcv.setBounds(10, 172, 102, 23); - panel_1.add(lblKcv); txtbKCV = new JTextField(); txtbKCV.setBackground(Color.WHITE); txtbKCV.setFont(new Font("Tahoma", Font.PLAIN, 14)); txtbKCV.setEditable(false); txtbKCV.setColumns(10); - txtbKCV.setBounds(112, 172, 225, 23); - panel_1.add(txtbKCV); JButton btnCalcKCV = new JButton("CALC"); btnCalcKCV.setBackground(Color.WHITE); @@ -338,21 +361,63 @@ public void actionPerformed(ActionEvent e) { } } }); - btnCalcKCV.setBounds(347, 172, 95, 23); - panel_1.add(btnCalcKCV); + GroupLayout gl_panel_1 = new GroupLayout(panel_1); + gl_panel_1.setHorizontalGroup( + gl_panel_1.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(10) + .addComponent(panel_2, GroupLayout.PREFERRED_SIZE, 432, GroupLayout.PREFERRED_SIZE)) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(10) + .addComponent(lblAliasChiave, GroupLayout.PREFERRED_SIZE, 102, GroupLayout.PREFERRED_SIZE) + .addComponent(txtbAliasChiave, GroupLayout.PREFERRED_SIZE, 330, GroupLayout.PREFERRED_SIZE)) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(10) + .addComponent(lblKcv, GroupLayout.PREFERRED_SIZE, 102, GroupLayout.PREFERRED_SIZE) + .addComponent(txtbKCV, GroupLayout.PREFERRED_SIZE, 225, GroupLayout.PREFERRED_SIZE) + .addGap(10) + .addComponent(btnCalcKCV, GroupLayout.PREFERRED_SIZE, 95, GroupLayout.PREFERRED_SIZE)) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(22) + .addComponent(btnGeneraChiave, GroupLayout.PREFERRED_SIZE, 148, GroupLayout.PREFERRED_SIZE) + .addGap(13) + .addComponent(chckbxChiaveEsterna, GroupLayout.PREFERRED_SIZE, 154, GroupLayout.PREFERRED_SIZE)) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(22) + .addComponent(btnImportaChiave, GroupLayout.PREFERRED_SIZE, 148, GroupLayout.PREFERRED_SIZE)) + ); + gl_panel_1.setVerticalGroup( + gl_panel_1.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(11) + .addComponent(panel_2, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE) + .addGap(11) + .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING) + .addComponent(lblAliasChiave, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE) + .addComponent(txtbAliasChiave, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGap(11) + .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING) + .addComponent(lblKcv, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE) + .addComponent(txtbKCV, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(btnCalcKCV)) + .addGap(23) + .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING) + .addComponent(btnGeneraChiave, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE) + .addComponent(chckbxChiaveEsterna)) + .addGap(11) + .addComponent(btnImportaChiave, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE)) + ); + panel_1.setLayout(gl_panel_1); JPanel panel_3 = new JPanel(); panel_3.setBackground(Color.DARK_GRAY); tabbedPane.addTab("KEYS", null, panel_3, null); - panel_3.setLayout(null); JPanel panel3432 = new JPanel(); panel3432.setLayout(null); panel3432.setForeground(Color.WHITE); panel3432.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "KEYS", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(255, 255, 255))); panel3432.setBackground(Color.DARK_GRAY); - panel3432.setBounds(22, 11, 407, 220); - panel_3.add(panel3432); JComboBox cmbBoxKeyWallet_1_1 = new JComboBox(); cmbBoxKeyWallet_1_1.setBackground(Color.WHITE); @@ -481,17 +546,29 @@ public void actionPerformed(ActionEvent e) { lblKcv_1.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblKcv_1.setBounds(22, 128, 78, 23); panel3432.add(lblKcv_1); + GroupLayout gl_panel_3 = new GroupLayout(panel_3); + gl_panel_3.setHorizontalGroup( + gl_panel_3.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_3.createSequentialGroup() + .addGap(22) + .addComponent(panel3432, GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE) + .addGap(23)) + ); + gl_panel_3.setVerticalGroup( + gl_panel_3.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_3.createSequentialGroup() + .addGap(11) + .addComponent(panel3432, GroupLayout.PREFERRED_SIZE, 220, GroupLayout.PREFERRED_SIZE)) + ); + panel_3.setLayout(gl_panel_3); JPanel panel_4 = new JPanel(); panel_4.setBackground(Color.DARK_GRAY); tabbedPane.addTab("ECDH", null, panel_4, null); - panel_4.setLayout(null); JPanel panel_5 = new JPanel(); panel_5.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "MY PUBLIC KEY", TitledBorder.LEADING, TitledBorder.TOP, null, Color.WHITE)); panel_5.setBackground(Color.DARK_GRAY); - panel_5.setBounds(10, 5, 432, 83); - panel_4.add(panel_5); panel_5.setLayout(new BorderLayout(0, 0)); JTextArea txtbMyPublicKey = new JTextArea(); @@ -502,8 +579,6 @@ public void actionPerformed(ActionEvent e) { JPanel panel_5_1 = new JPanel(); panel_5_1.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "OTHER PUBLIC KEY", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(255, 255, 255))); panel_5_1.setBackground(Color.DARK_GRAY); - panel_5_1.setBounds(10, 89, 432, 94); - panel_4.add(panel_5_1); panel_5_1.setLayout(new BorderLayout(0, 0)); JTextArea txtbOtherPublicKey = new JTextArea(); @@ -514,8 +589,6 @@ public void actionPerformed(ActionEvent e) { JPanel panel_5_1_1 = new JPanel(); panel_5_1_1.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "KEY", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(255, 255, 255))); panel_5_1_1.setBackground(Color.DARK_GRAY); - panel_5_1_1.setBounds(10, 183, 432, 62); - panel_4.add(panel_5_1_1); panel_5_1_1.setLayout(new BorderLayout(0, 0)); JTextArea txtbGeneratedECKey = new JTextArea(); @@ -527,14 +600,10 @@ public void actionPerformed(ActionEvent e) { JLabel lblNewLabel = new JLabel("KCV:"); lblNewLabel.setForeground(Color.WHITE); lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14)); - lblNewLabel.setBounds(10, 256, 46, 14); - panel_4.add(lblNewLabel); JLabel txtbKCVEC = new JLabel("---"); txtbKCVEC.setForeground(Color.WHITE); txtbKCVEC.setFont(new Font("Tahoma", Font.BOLD, 14)); - txtbKCVEC.setBounds(49, 256, 74, 14); - panel_4.add(txtbKCVEC); JButton btnCalculateECDH = new JButton("2 - CALC"); btnCalculateECDH.setBackground(Color.WHITE); @@ -553,8 +622,6 @@ public void actionPerformed(ActionEvent e) { } }); - btnCalculateECDH.setBounds(175, 290, 89, 52); - panel_4.add(btnCalculateECDH); btnInitECDH = new JButton("1 - INIT"); btnInitECDH.setBackground(Color.WHITE); @@ -571,8 +638,6 @@ public void actionPerformed(ActionEvent e) { } } }); - btnInitECDH.setBounds(76, 290, 89, 52); - panel_4.add(btnInitECDH); @@ -594,8 +659,57 @@ public void actionPerformed(ActionEvent e) { } }); btnKeystoreAdd.setBackground(Color.WHITE); - btnKeystoreAdd.setBounds(274, 290, 89, 52); - panel_4.add(btnKeystoreAdd); + GroupLayout gl_panel_4 = new GroupLayout(panel_4); + gl_panel_4.setHorizontalGroup( + gl_panel_4.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_4.createSequentialGroup() + .addGap(10) + .addGroup(gl_panel_4.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_4.createSequentialGroup() + .addGap(39) + .addComponent(txtbKCVEC, GroupLayout.PREFERRED_SIZE, 74, GroupLayout.PREFERRED_SIZE)) + .addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE))) + .addGroup(gl_panel_4.createSequentialGroup() + .addGap(76) + .addComponent(btnInitECDH, GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE) + .addGap(10) + .addComponent(btnCalculateECDH, GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE) + .addGap(10) + .addComponent(btnKeystoreAdd, GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE) + .addGap(89)) + .addGroup(gl_panel_4.createSequentialGroup() + .addContainerGap() + .addComponent(panel_5, GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE) + .addContainerGap()) + .addGroup(gl_panel_4.createSequentialGroup() + .addContainerGap() + .addComponent(panel_5_1, GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE) + .addContainerGap()) + .addGroup(gl_panel_4.createSequentialGroup() + .addContainerGap() + .addComponent(panel_5_1_1, GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE) + .addContainerGap()) + ); + gl_panel_4.setVerticalGroup( + gl_panel_4.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_4.createSequentialGroup() + .addGap(5) + .addComponent(panel_5, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE) + .addGap(1) + .addComponent(panel_5_1, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(panel_5_1_1, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE) + .addGap(11) + .addGroup(gl_panel_4.createParallelGroup(Alignment.LEADING) + .addComponent(txtbKCVEC, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE) + .addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)) + .addGap(20) + .addGroup(gl_panel_4.createParallelGroup(Alignment.LEADING) + .addComponent(btnInitECDH, GroupLayout.PREFERRED_SIZE, 52, GroupLayout.PREFERRED_SIZE) + .addComponent(btnCalculateECDH, GroupLayout.PREFERRED_SIZE, 52, GroupLayout.PREFERRED_SIZE) + .addComponent(btnKeystoreAdd, GroupLayout.PREFERRED_SIZE, 52, GroupLayout.PREFERRED_SIZE))) + ); + panel_4.setLayout(gl_panel_4); if(prefs.getBoolean("lineWrap", false)) { chckbLineWrapping.setSelected(true); diff --git a/src/it/HackerInside/TextEncryptionUtility/TextEncryptionUtil_Main.java b/src/it/HackerInside/TextEncryptionUtility/TextEncryptionUtil_Main.java index c21ac52..8177048 100644 --- a/src/it/HackerInside/TextEncryptionUtility/TextEncryptionUtil_Main.java +++ b/src/it/HackerInside/TextEncryptionUtility/TextEncryptionUtil_Main.java @@ -55,6 +55,8 @@ import java.awt.Component; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; public class TextEncryptionUtil_Main { @@ -127,10 +129,10 @@ public static String passwordInput(String title) { * Initialize the contents of the frame. */ private void initialize() { + frmHackerinsideTextEncryption = new JFrame(); frmHackerinsideTextEncryption.setIconImage(Toolkit.getDefaultToolkit().getImage(TextEncryptionUtil_Main.class.getResource("/it/HackerInside/TextEncryptionUtility/res/data-encryption.png"))); frmHackerinsideTextEncryption.setTitle("HackerInside Text Encryption Utility | Main"); - frmHackerinsideTextEncryption.setResizable(false); frmHackerinsideTextEncryption.setBounds(100, 100, 1048, 737); frmHackerinsideTextEncryption.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -139,21 +141,15 @@ private void initialize() { panel.setForeground(Color.WHITE); panel.setBackground(Color.DARK_GRAY); frmHackerinsideTextEncryption.getContentPane().add(panel, BorderLayout.CENTER); - panel.setLayout(null); JPanel panel_1 = new JPanel(); panel_1.setBackground(Color.DARK_GRAY); panel_1.setForeground(Color.WHITE); panel_1.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "Key Settings", TitledBorder.LEADING, TitledBorder.TOP, null, Color.WHITE)); - panel_1.setBounds(10, 11, 1012, 65); - panel.add(panel_1); - panel_1.setLayout(null); JLabel lblNewLabel = new JLabel("KEY ID:"); lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 18)); lblNewLabel.setForeground(Color.WHITE); - lblNewLabel.setBounds(10, 27, 74, 14); - panel_1.add(lblNewLabel); JTextArea txtbData = new JTextArea(); txtbData.setLineWrap(true); @@ -172,8 +168,6 @@ public void mouseWheelMoved(MouseWheelEvent e) { } } }); - scrollPane.setBounds(10, 87, 1012, 600); - panel.add(scrollPane); JComboBox cmbKID = new JComboBox(); cmbKID.setBackground(Color.WHITE); @@ -193,8 +187,6 @@ public void popupMenuWillBecomeVisible(PopupMenuEvent e) { }); cmbKID.setToolTipText("KeyStore Key name"); cmbKID.setFont(new Font("Tahoma", Font.PLAIN, 16)); - cmbKID.setBounds(79, 17, 252, 36); - panel_1.add(cmbKID); JButton btnEncrypt = new JButton("ENCRYPT"); btnEncrypt.setBackground(Color.WHITE); @@ -218,8 +210,6 @@ public void actionPerformed(ActionEvent e) { } }); btnEncrypt.setFont(new Font("Tahoma", Font.BOLD, 13)); - btnEncrypt.setBounds(341, 17, 98, 36); - panel_1.add(btnEncrypt); JButton btnDecrypt = new JButton("DECRYPT"); btnDecrypt.setBackground(Color.WHITE); @@ -245,8 +235,6 @@ public void actionPerformed(ActionEvent e) { } }); btnDecrypt.setFont(new Font("Tahoma", Font.BOLD, 13)); - btnDecrypt.setBounds(449, 17, 98, 36); - panel_1.add(btnDecrypt); JButton btnZeroize = new JButton("ZEROIZE"); btnZeroize.addActionListener(new ActionListener() { @@ -263,8 +251,6 @@ public void actionPerformed(ActionEvent e) { btnZeroize.setForeground(Color.WHITE); btnZeroize.setBackground(Color.RED); btnZeroize.setFont(new Font("Tahoma", Font.BOLD, 14)); - btnZeroize.setBounds(904, 17, 98, 36); - panel_1.add(btnZeroize); JButton btnSettings = new JButton(""); btnSettings.setBackground(Color.WHITE); @@ -276,15 +262,11 @@ public void actionPerformed(ActionEvent e) { } }); btnSettings.setToolTipText("User Settings"); - btnSettings.setBounds(850, 17, 40, 36); - panel_1.add(btnSettings); btnSettings.setIcon(new ImageIcon(TextEncryptionUtil_Main.class.getResource("/it/HackerInside/TextEncryptionUtility/res/icons8-support-30.png"))); JLabel lblFrancescoValentini = new JLabel("Francesco Valentini - 2023"); lblFrancescoValentini.setForeground(Color.WHITE); lblFrancescoValentini.setFont(new Font("Tahoma", Font.PLAIN, 14)); - lblFrancescoValentini.setBounds(613, 28, 173, 14); - panel_1.add(lblFrancescoValentini); // TextArea prefs @@ -323,6 +305,75 @@ public void actionPerformed(ActionEvent e) { } }); popupMenu.add(btnSaveFile); + GroupLayout gl_panel = new GroupLayout(panel); + gl_panel.setHorizontalGroup( + gl_panel.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel.createSequentialGroup() + .addGap(10) + .addGroup(gl_panel.createParallelGroup(Alignment.TRAILING) + .addComponent(scrollPane, Alignment.LEADING) + .addComponent(panel_1, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 1012, Short.MAX_VALUE)) + .addGap(10)) + ); + gl_panel.setVerticalGroup( + gl_panel.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel.createSequentialGroup() + .addGap(11) + .addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 65, GroupLayout.PREFERRED_SIZE) + .addGap(11) + .addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE) + .addContainerGap()) + ); + GroupLayout gl_panel_1 = new GroupLayout(panel_1); + gl_panel_1.setHorizontalGroup( + gl_panel_1.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(4) + .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_1.createSequentialGroup() + .addComponent(lblNewLabel, GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE) + .addGap(247)) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(69) + .addComponent(cmbKID, 0, 252, Short.MAX_VALUE))) + .addGap(10) + .addComponent(btnEncrypt, GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE) + .addGap(10) + .addComponent(btnDecrypt, GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE) + .addGap(66) + .addComponent(lblFrancescoValentini, GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE) + .addGap(64) + .addComponent(btnSettings, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE) + .addGap(14) + .addComponent(btnZeroize, GroupLayout.PREFERRED_SIZE, 102, GroupLayout.PREFERRED_SIZE)) + ); + gl_panel_1.setVerticalGroup( + gl_panel_1.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(1) + .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(10) + .addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)) + .addComponent(cmbKID, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE))) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(1) + .addComponent(btnEncrypt, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(1) + .addComponent(btnDecrypt, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(12) + .addComponent(lblFrancescoValentini, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(1) + .addComponent(btnSettings, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(1) + .addComponent(btnZeroize, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)) + ); + panel_1.setLayout(gl_panel_1); + panel.setLayout(gl_panel); } public static void updateKeysList(JComboBox jcombo) throws Exception { // Aggiorna la lista delle chiavi @@ -500,6 +551,7 @@ private static String readTextFile(File f) { while(s.hasNextLine()) { data = data + s.nextLine(); } + s.close(); } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(null,e.getMessage()); e.printStackTrace();