├── encrypted_password.txt ├── PasswordManagerGUI.class ├── PasswordDecryptManagerGUI.class ├── .gitignore ├── README.md ├── PasswordDecryptManagerGUI.java └── PasswordManagerGUI.java /encrypted_password.txt: -------------------------------------------------------------------------------- 1 | xEuiZEaPu9gp1TtYGL9cptvMq6ZaaI/lRY1wOLSMW2+vAVQelgEhTxvrrKVkGEel -------------------------------------------------------------------------------- /PasswordManagerGUI.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darksolopic/PasswordManagerGUI/HEAD/PasswordManagerGUI.class -------------------------------------------------------------------------------- /PasswordDecryptManagerGUI.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darksolopic/PasswordManagerGUI/HEAD/PasswordDecryptManagerGUI.class -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | replay_pid* 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PasswordManagerGUI 2 | The program is a password manager implemented in Java using Swing for the graphical user interface. It allows users to encrypt and decrypt passwords using a master password. The passwords are encrypted and decrypted using AES encryption with CBC mode and PKCS5Padding. 3 | 4 | Features: 5 | 1. Encryption and Decryption: Users can encrypt their passwords using a master password and decrypt them when needed. 6 | 2. File Storage: Encrypted passwords are stored in a file named "encrypted_password.txt" for future reference. 7 | 3. AES Encryption: The application utilizes AES encryption with CBC mode and PKCS5 padding to ensure robust security. 8 | 4. User-Friendly Interface: The GUI provides a simple and intuitive way for users to interact with the decryption functionality. 9 | 10 | 11 | How to Use: 12 | 13 | Encryption: 14 | --Enter your master password and the password you want to encrypt. 15 | --Click the "Encrypt" button. 16 | --The encrypted password will be displayed, and it will also be saved to the file "encrypted_password.txt". 17 | 18 | 19 | Decryption: 20 | --Enter your master password and the encrypted password. 21 | --Click the "Decrypt" button. 22 | --The decrypted password will be displayed. 23 | 24 | How to Use: Password Decrypt Manager GUI only for decryption. 25 | --Enter your master password and the encrypted password you want to decrypt. 26 | --Click the "Decrypt" button. 27 | --The decrypted password will be displayed in the designated field. 28 | 29 | Installation: 30 | --Clone the repository to your local machine. 31 | --Open the project in your preferred Java IDE. 32 | --Compile and run the PasswordManagerGUI.java file. 33 | --Compile and run the PasswordDecryptManagerGUI.java file. 34 | 35 | Contributors: 36 | Gautam kumar Sinha 37 | 38 | License: 39 | This project is licensed under the None. 40 | -------------------------------------------------------------------------------- /PasswordDecryptManagerGUI.java: -------------------------------------------------------------------------------- 1 | import javax.swing.*; 2 | import java.awt.*; 3 | import java.awt.event.ActionEvent; 4 | import java.awt.event.ActionListener; 5 | import java.io.*; 6 | import java.security.spec.KeySpec; 7 | import javax.crypto.Cipher; 8 | import javax.crypto.SecretKey; 9 | import javax.crypto.SecretKeyFactory; 10 | import javax.crypto.spec.IvParameterSpec; 11 | import javax.crypto.spec.PBEKeySpec; 12 | import javax.crypto.spec.SecretKeySpec; 13 | import java.security.SecureRandom; 14 | import java.util.Base64; 15 | import java.nio.charset.StandardCharsets; 16 | 17 | public class PasswordDecryptManagerGUI extends JFrame implements ActionListener { 18 | 19 | private static final String SECRET_KEY_ALGORITHM = "AES"; 20 | private static final String CIPHER_ALGORITHM = "AES/CBC/PKCS5Padding"; 21 | private static final int KEY_LENGTH = 256; 22 | private static final int SALT_LENGTH = 16; 23 | private static final int ITERATIONS = 65536; 24 | private static final int IV_LENGTH = 16; 25 | private static final String ENCRYPTED_PASSWORD_FILE = "encrypted_password.txt"; 26 | 27 | private JTextField masterPasswordField, encryptedPasswordField, decryptedPasswordField; 28 | 29 | public PasswordDecryptManagerGUI() { 30 | setTitle("Password Manager"); 31 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 32 | setSize(500, 300); 33 | setLocationRelativeTo(null); 34 | 35 | JPanel mainPanel = new JPanel(); 36 | mainPanel.setLayout(new GridLayout(4, 2, 10, 10)); 37 | mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); 38 | 39 | Font labelFont = new Font("Arial", Font.PLAIN, 16); // Adjust the font size as needed 40 | Font textFieldFont = new Font("Arial", Font.PLAIN, 16); // Adjust the font size as needed 41 | 42 | JLabel masterPasswordLabel = new JLabel("Master Password:"); 43 | masterPasswordLabel.setFont(labelFont); 44 | masterPasswordField = new JPasswordField(); 45 | masterPasswordField.setFont(textFieldFont); 46 | 47 | 48 | JLabel encryptedPasswordLabel = new JLabel("Encrypted Password:"); 49 | encryptedPasswordLabel.setFont(labelFont); 50 | encryptedPasswordField = new JTextField(); 51 | encryptedPasswordField.setFont(textFieldFont); 52 | 53 | 54 | JLabel decryptedPasswordLabel = new JLabel("Decrypted Password:"); 55 | decryptedPasswordLabel.setFont(labelFont); 56 | decryptedPasswordField = new JTextField(); 57 | decryptedPasswordField.setEditable(false); 58 | decryptedPasswordField.setFont(textFieldFont); 59 | 60 | JButton decryptButton = new JButton("Decrypt"); 61 | 62 | decryptButton.addActionListener(this); 63 | 64 | mainPanel.add(masterPasswordLabel); 65 | mainPanel.add(masterPasswordField); 66 | mainPanel.add(encryptedPasswordLabel); 67 | mainPanel.add(encryptedPasswordField); 68 | mainPanel.add(decryptedPasswordLabel); 69 | mainPanel.add(decryptedPasswordField); 70 | mainPanel.add(decryptButton); 71 | 72 | setContentPane(mainPanel); 73 | setVisible(true); 74 | } 75 | 76 | private static SecretKey deriveKey(char[] masterPassword, byte[] salt) throws Exception { 77 | KeySpec spec = new PBEKeySpec(masterPassword, salt, ITERATIONS, KEY_LENGTH); 78 | SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); 79 | byte[] keyBytes = factory.generateSecret(spec).getEncoded(); 80 | return new SecretKeySpec(keyBytes, SECRET_KEY_ALGORITHM); 81 | } 82 | 83 | private String decrypt(String masterPassword, String encryptedPassword) { 84 | try { 85 | byte[] combined = Base64.getDecoder().decode(encryptedPassword); 86 | byte[] salt = new byte[SALT_LENGTH]; 87 | byte[] iv = new byte[IV_LENGTH]; 88 | byte[] encrypted = new byte[combined.length - salt.length - iv.length]; 89 | System.arraycopy(combined, 0, salt, 0, salt.length); 90 | System.arraycopy(combined, salt.length, iv, 0, iv.length); 91 | System.arraycopy(combined, salt.length + iv.length, encrypted, 0, encrypted.length); 92 | SecretKey key = deriveKey(masterPassword.toCharArray(), salt); 93 | Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); 94 | cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv)); 95 | byte[] decrypted = cipher.doFinal(encrypted); 96 | return new String(decrypted, StandardCharsets.UTF_8); // Ensure proper charset 97 | } catch (Exception e) { 98 | JOptionPane.showMessageDialog(this, "Decryption failed: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 99 | return null; 100 | } 101 | } 102 | 103 | 104 | @Override 105 | public void actionPerformed(ActionEvent e) { 106 | if (e.getActionCommand().equals("Decrypt")) { 107 | String masterPassword = masterPasswordField.getText(); 108 | String encryptedPassword = encryptedPasswordField.getText(); 109 | String decryptedPassword = decrypt(masterPassword, encryptedPassword); 110 | if (decryptedPassword != null) { 111 | decryptedPasswordField.setText(decryptedPassword); 112 | } 113 | } 114 | } 115 | 116 | public static void main(String[] args) { 117 | SwingUtilities.invokeLater(PasswordDecryptManagerGUI::new); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /PasswordManagerGUI.java: -------------------------------------------------------------------------------- 1 | import javax.swing.*; 2 | import java.awt.*; 3 | import java.awt.event.ActionEvent; 4 | import java.awt.event.ActionListener; 5 | import java.io.*; 6 | import java.security.spec.KeySpec; 7 | import javax.crypto.Cipher; 8 | import javax.crypto.SecretKey; 9 | import javax.crypto.SecretKeyFactory; 10 | import javax.crypto.spec.IvParameterSpec; 11 | import javax.crypto.spec.PBEKeySpec; 12 | import javax.crypto.spec.SecretKeySpec; 13 | import java.security.SecureRandom; 14 | import java.util.Base64; 15 | 16 | public class PasswordManagerGUI extends JFrame implements ActionListener { 17 | 18 | private static final String SECRET_KEY_ALGORITHM = "AES"; 19 | private static final String CIPHER_ALGORITHM = "AES/CBC/PKCS5Padding"; 20 | private static final int KEY_LENGTH = 256; 21 | private static final int SALT_LENGTH = 16; 22 | private static final int ITERATIONS = 65536; 23 | private static final int IV_LENGTH = 16; 24 | private static final String ENCRYPTED_PASSWORD_FILE = "encrypted_password.txt"; 25 | 26 | private JTextField masterPasswordField, passwordField, encryptedPasswordField, decryptedPasswordField, encryptedPasswordfileField; 27 | 28 | public PasswordManagerGUI() { 29 | setTitle("Password Manager"); 30 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 31 | setSize(600, 500); 32 | setLocationRelativeTo(null); 33 | 34 | JPanel mainPanel = new JPanel(); 35 | mainPanel.setLayout(new GridLayout(6, 2, 10, 10)); 36 | mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); 37 | 38 | Font labelFont = new Font("Arial", Font.PLAIN, 16); // Adjust the font size as needed 39 | Font textFieldFont = new Font("Arial", Font.PLAIN, 16); // Adjust the font size as needed 40 | 41 | 42 | JLabel masterPasswordLabel = new JLabel("Master Password:"); 43 | masterPasswordLabel.setFont(labelFont); 44 | masterPasswordField = new JPasswordField(); 45 | masterPasswordField.setFont(textFieldFont); 46 | 47 | JLabel passwordLabel = new JLabel("Password:"); 48 | passwordLabel.setFont(labelFont); 49 | passwordField = new JPasswordField(); 50 | passwordField.setFont(textFieldFont); 51 | 52 | JLabel encryptedPasswordLabel = new JLabel("Encrypted Password:"); 53 | encryptedPasswordLabel.setFont(labelFont); 54 | encryptedPasswordField = new JTextField(); 55 | encryptedPasswordField.setEditable(false); 56 | encryptedPasswordField.setFont(textFieldFont); 57 | 58 | JLabel encryptedPasswordfileLabel = new JLabel("Encrypted Password, Check File!"); 59 | encryptedPasswordfileLabel.setFont(labelFont); 60 | encryptedPasswordfileField = new JTextField(); 61 | encryptedPasswordfileField.setEditable(false); 62 | encryptedPasswordfileField.setFont(textFieldFont); 63 | 64 | 65 | JLabel decryptedPasswordLabel = new JLabel("Decrypted Password:"); 66 | decryptedPasswordLabel.setFont(labelFont); 67 | decryptedPasswordField = new JTextField(); 68 | decryptedPasswordField.setEditable(false); 69 | decryptedPasswordField.setFont(textFieldFont); 70 | 71 | JButton encryptButton = new JButton("Encrypt"); 72 | JButton decryptButton = new JButton("Decrypt"); 73 | 74 | encryptButton.addActionListener(this); 75 | decryptButton.addActionListener(this); 76 | 77 | mainPanel.add(masterPasswordLabel); 78 | mainPanel.add(masterPasswordField); 79 | mainPanel.add(passwordLabel); 80 | mainPanel.add(passwordField); 81 | mainPanel.add(encryptedPasswordLabel); 82 | mainPanel.add(encryptedPasswordField); 83 | mainPanel.add(encryptedPasswordfileLabel); 84 | mainPanel.add(encryptedPasswordfileField); 85 | mainPanel.add(decryptedPasswordLabel); 86 | mainPanel.add(decryptedPasswordField); 87 | mainPanel.add(encryptButton); 88 | mainPanel.add(decryptButton); 89 | 90 | setContentPane(mainPanel); 91 | setVisible(true); 92 | } 93 | 94 | private static byte[] generateSalt() { 95 | byte[] salt = new byte[SALT_LENGTH]; 96 | new SecureRandom().nextBytes(salt); 97 | return salt; 98 | } 99 | 100 | private static SecretKey deriveKey(char[] masterPassword, byte[] salt) throws Exception { 101 | KeySpec spec = new PBEKeySpec(masterPassword, salt, ITERATIONS, KEY_LENGTH); 102 | SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); 103 | byte[] keyBytes = factory.generateSecret(spec).getEncoded(); 104 | return new SecretKeySpec(keyBytes, SECRET_KEY_ALGORITHM); 105 | } 106 | 107 | private String encrypt(String masterPassword, String password) { 108 | try { 109 | byte[] salt = generateSalt(); 110 | SecretKey key = deriveKey(masterPassword.toCharArray(), salt); 111 | Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); 112 | byte[] iv = new byte[IV_LENGTH]; 113 | new SecureRandom().nextBytes(iv); 114 | IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); 115 | cipher.init(Cipher.ENCRYPT_MODE, key, ivParameterSpec); 116 | byte[] encrypted = cipher.doFinal(password.getBytes()); 117 | byte[] combined = new byte[salt.length + iv.length + encrypted.length]; 118 | System.arraycopy(salt, 0, combined, 0, salt.length); 119 | System.arraycopy(iv, 0, combined, salt.length, iv.length); 120 | System.arraycopy(encrypted, 0, combined, salt.length + iv.length, encrypted.length); 121 | String encryptedPassword = Base64.getEncoder().encodeToString(combined); 122 | 123 | // Write encrypted password to file 124 | writeToFile(encryptedPassword); 125 | 126 | return encryptedPassword; 127 | } catch (Exception e) { 128 | JOptionPane.showMessageDialog(this, "Encryption failed: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 129 | return null; 130 | } 131 | } 132 | 133 | private void writeToFile(String encryptedPassword) { 134 | try (BufferedWriter writer = new BufferedWriter(new FileWriter(ENCRYPTED_PASSWORD_FILE))) { 135 | writer.write(encryptedPassword); 136 | } catch (IOException e) { 137 | JOptionPane.showMessageDialog(this, "Failed to write encrypted password to file", "Error", JOptionPane.ERROR_MESSAGE); 138 | } 139 | } 140 | 141 | private String decrypt(String masterPassword, String encryptedPassword) { 142 | try { 143 | byte[] combined = Base64.getDecoder().decode(encryptedPassword); 144 | byte[] salt = new byte[SALT_LENGTH]; 145 | byte[] iv = new byte[IV_LENGTH]; 146 | byte[] encrypted = new byte[combined.length - salt.length - iv.length]; 147 | System.arraycopy(combined, 0, salt, 0, salt.length); 148 | System.arraycopy(combined, salt.length, iv, 0, iv.length); 149 | System.arraycopy(combined, salt.length + iv.length, encrypted, 0, encrypted.length); 150 | SecretKey key = deriveKey(masterPassword.toCharArray(), salt); 151 | Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); 152 | cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv)); 153 | byte[] decrypted = cipher.doFinal(encrypted); 154 | return new String(decrypted); 155 | } catch (Exception e) { 156 | JOptionPane.showMessageDialog(this, "Decryption failed: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 157 | return null; 158 | } 159 | } 160 | 161 | @Override 162 | public void actionPerformed(ActionEvent e) { 163 | if (e.getActionCommand().equals("Encrypt")) { 164 | String masterPassword = masterPasswordField.getText(); 165 | String password = passwordField.getText(); 166 | String encryptedPassword = encrypt(masterPassword, password); 167 | if (encryptedPassword != null) { 168 | encryptedPasswordField.setText(encryptedPassword); 169 | encryptedPasswordfileField.setText("Encrypted! Check file."); 170 | } 171 | } else if (e.getActionCommand().equals("Decrypt")) { 172 | String masterPassword = masterPasswordField.getText(); 173 | String encryptedPassword = encryptedPasswordField.getText(); 174 | String decryptedPassword = decrypt(masterPassword, encryptedPassword); 175 | if (decryptedPassword != null) { 176 | decryptedPasswordField.setText(decryptedPassword); 177 | } 178 | } 179 | } 180 | 181 | public static void main(String[] args) { 182 | SwingUtilities.invokeLater(PasswordManagerGUI::new); 183 | } 184 | } 185 | --------------------------------------------------------------------------------