MCPcopy Index your code
hub / github.com/darksolopic/PasswordManagerGUI / decrypt

Method decrypt

PasswordManagerGUI.java:141–159  ·  view source on GitHub ↗
(String masterPassword, String encryptedPassword)

Source from the content-addressed store, hash-verified

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) {

Callers 1

actionPerformedMethod · 0.95

Calls 1

deriveKeyMethod · 0.95

Tested by

no test coverage detected