Skip to content

Commit 18aaa55

Browse files
authored
Merge pull request #166 from dbohannon/dbohannon-clear-spec
Prevent password leak in memory
2 parents 0fc9c57 + e4088fa commit 18aaa55

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main/java/com/password4j/PBKDF2Function.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,14 @@ protected static SecretKey internalHash(char[] plain, byte[] salt, String algori
128128
{
129129
SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(ALGORITHM_PREFIX + algorithm);
130130
PBEKeySpec spec = new PBEKeySpec(plain, salt, iterations, length);
131-
return secretKeyFactory.generateSecret(spec);
131+
try
132+
{
133+
return secretKeyFactory.generateSecret(spec);
134+
}
135+
finally
136+
{
137+
spec.clearPassword();
138+
}
132139
}
133140

134141
protected static String getUID(String algorithm, int iterations, int length)

0 commit comments

Comments
 (0)