Skip to content

Commit 4c6f41c

Browse files
author
Jari Hämäläinen
committed
Properly sanitize key material
Use Arrays.fill() to sanitize key material.
1 parent f2fd709 commit 4c6f41c

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

android-database-sqlcipher/src/main/java/net/sqlcipher/database/SQLiteDatabase.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.nio.charset.Charset;
3838
import java.text.SimpleDateFormat;
3939
import java.util.ArrayList;
40+
import java.util.Arrays;
4041
import java.util.HashMap;
4142
import java.util.HashSet;
4243
import java.util.Iterator;
@@ -118,9 +119,7 @@ public void changePassword(String password) throws SQLiteException {
118119
if (password != null) {
119120
byte[] keyMaterial = getBytes(password.toCharArray());
120121
rekey(keyMaterial);
121-
for(byte data : keyMaterial) {
122-
data = 0;
123-
}
122+
Arrays.fill(keyMaterial, (byte) 0);
124123
}
125124
}
126125

@@ -143,9 +142,7 @@ public void changePassword(char[] password) throws SQLiteException {
143142
if (password != null) {
144143
byte[] keyMaterial = getBytes(password);
145144
rekey(keyMaterial);
146-
for(byte data : keyMaterial) {
147-
data = 0;
148-
}
145+
Arrays.fill(keyMaterial, (byte) 0);
149146
}
150147
}
151148

@@ -2537,9 +2534,7 @@ public void run() {
25372534
}
25382535
}
25392536
if(keyMaterial != null && keyMaterial.length > 0) {
2540-
for(byte data : keyMaterial) {
2541-
data = 0;
2542-
}
2537+
Arrays.fill(keyMaterial, (byte) 0);
25432538
}
25442539
}
25452540

0 commit comments

Comments
 (0)