Skip to content

Commit 6033da7

Browse files
committed
feat: password cleared when no longer needed
1 parent 09ef318 commit 6033da7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/FileEncryptor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public static void encrypt(char[] password, String inputPath, String outputPath)
109109
final byte[] key = generateKey(password, salt, 128);
110110
final byte[] macKey = generateKey(password, macSalt, 256);
111111

112+
// Password no longer needed
113+
Arrays.fill(password, '\0'); password = null;
114+
112115
SecretKeySpec macKeySpec = new SecretKeySpec(macKey, HASH_AlGORITHM);
113116

114117
Mac hmac = Mac.getInstance(HASH_AlGORITHM);
@@ -244,6 +247,9 @@ private static boolean writeDecryptedFile(Path inputPath, Path outputPath, char[
244247

245248
final byte[] key = generateKey(password, salt, 128);
246249
final byte[] macKey = generateKey(password, macSalt, 256);
250+
251+
// Password no longer needed
252+
Arrays.fill(password, '\0'); password = null;
247253

248254
// Create key specifications
249255
SecretKeySpec macKeySpec = new SecretKeySpec(macKey, HASH_AlGORITHM);

0 commit comments

Comments
 (0)