Skip to content

Commit a25949a

Browse files
committed
Update SQLCipher to the latest version
1 parent 81a4665 commit a25949a

File tree

6 files changed

+33
-26
lines changed

6 files changed

+33
-26
lines changed

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ task clean(type: Delete) {
2727
delete rootProject.buildDir
2828
}
2929
ext {
30-
compileSdk = 33
31-
targetSdk = 33
32-
minSdk = 14
33-
}
30+
compileSdk = 34
31+
targetSdk = 34
32+
minSdk = 21
33+
}

debug-db-encrypt/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ android {
1919

2020
dependencies {
2121
api project(':debug-db-base')
22-
implementation 'net.zetetic:android-database-sqlcipher:3.5.9'
22+
implementation 'androidx.sqlite:sqlite:2.4.0'
23+
implementation 'net.zetetic:sqlcipher-android:4.6.1'
2324
testImplementation 'junit:junit:4.13.2'
2425
androidTestImplementation 'androidx.test:runner:1.5.2'
2526
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
26-
}
27+
}

debug-db-encrypt/src/main/java/com/amitshekhar/debug/encrypt/sqlite/DebugDBEncryptFactory.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44

55
import com.amitshekhar.sqlite.DBFactory;
66
import com.amitshekhar.sqlite.SQLiteDB;
7-
8-
import net.sqlcipher.database.SQLiteDatabase;
7+
import net.zetetic.database.sqlcipher.SQLiteDatabase;
98

109
public class DebugDBEncryptFactory implements DBFactory {
1110

11+
static {
12+
System.loadLibrary("sqlcipher");
13+
}
14+
1215
@Override
1316
public SQLiteDB create(Context context, String path, String password) {
14-
SQLiteDatabase.loadLibs(context);
15-
return new DebugEncryptSQLiteDB(SQLiteDatabase.openOrCreateDatabase(path, password, null));
17+
return new DebugEncryptSQLiteDB(SQLiteDatabase.openOrCreateDatabase(path, password, null, null));
1618
}
1719

1820
@Override

debug-db-encrypt/src/main/java/com/amitshekhar/debug/encrypt/sqlite/DebugEncryptSQLiteDB.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import android.database.SQLException;
66

77
import com.amitshekhar.sqlite.SQLiteDB;
8-
9-
import net.sqlcipher.database.SQLiteDatabase;
8+
import net.zetetic.database.sqlcipher.SQLiteDatabase;
109

1110
/**
1211
* Created by anandgaurav on 12/02/18.

sample-app-encrypt/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ android {
2424

2525
dependencies {
2626
debugImplementation project(':debug-db-encrypt')
27+
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
2728
implementation 'androidx.appcompat:appcompat:1.4.2'
28-
implementation 'net.zetetic:android-database-sqlcipher:3.5.9'
29+
implementation 'net.zetetic:sqlcipher-android:4.6.1'
2930
implementation "androidx.room:room-runtime:2.5.0"
3031
annotationProcessor "androidx.room:room-compiler:2.5.0"
3132
testImplementation 'junit:junit:4.13.2'

sample-app-encrypt/src/main/java/com/sample/encrypt/database/PersonDBHelper.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919

2020
package com.sample.encrypt.database;
2121

22+
import android.annotation.SuppressLint;
2223
import android.content.ContentValues;
2324
import android.content.Context;
2425
import android.database.Cursor;
2526

26-
import net.sqlcipher.DatabaseUtils;
27-
import net.sqlcipher.database.SQLiteDatabase;
28-
import net.sqlcipher.database.SQLiteOpenHelper;
27+
import net.zetetic.database.DatabaseUtils;
28+
import net.zetetic.database.sqlcipher.SQLiteDatabase;
29+
import net.zetetic.database.sqlcipher.SQLiteOpenHelper;
2930

3031
import java.util.ArrayList;
3132

@@ -39,10 +40,12 @@ public class PersonDBHelper extends SQLiteOpenHelper {
3940
public static final String PERSON_COLUMN_ADDRESS = "address";
4041
private static final String DB_PASSWORD = "a_password";
4142

42-
public PersonDBHelper(Context context) {
43+
static {
44+
System.loadLibrary("sqlcipher");
45+
}
4346

44-
super(context, DATABASE_NAME, null, 1);
45-
SQLiteDatabase.loadLibs(context);
47+
public PersonDBHelper(Context context) {
48+
super(context, DATABASE_NAME, DB_PASSWORD, null, 1, 0, null, null, false);
4649
}
4750

4851
@Override
@@ -60,7 +63,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
6063
}
6164

6265
public boolean insertPerson(String firstName, String lastName, String address) {
63-
SQLiteDatabase db = this.getWritableDatabase(DB_PASSWORD);
66+
SQLiteDatabase db = this.getWritableDatabase();
6467
ContentValues contentValues = new ContentValues();
6568
contentValues.put("first_name", firstName);
6669
contentValues.put("last_name", lastName);
@@ -71,19 +74,19 @@ public boolean insertPerson(String firstName, String lastName, String address) {
7174
}
7275

7376
public Cursor getData(int id) {
74-
SQLiteDatabase db = this.getReadableDatabase(DB_PASSWORD);
77+
SQLiteDatabase db = this.getReadableDatabase();
7578
Cursor res = db.rawQuery("select * from person where id=" + id + "", null);
7679
return res;
7780
}
7881

7982
public int numberOfRows() {
80-
SQLiteDatabase db = this.getReadableDatabase(DB_PASSWORD);
83+
SQLiteDatabase db = this.getReadableDatabase();
8184
int numRows = (int) DatabaseUtils.queryNumEntries(db, PERSON_TABLE_NAME);
8285
return numRows;
8386
}
8487

8588
public boolean updatePerson(Integer id, String firstName, String lastName, String address, float mileage) {
86-
SQLiteDatabase db = this.getWritableDatabase(DB_PASSWORD);
89+
SQLiteDatabase db = this.getWritableDatabase();
8790
ContentValues contentValues = new ContentValues();
8891
contentValues.put("first_name", firstName);
8992
contentValues.put("last_name", lastName);
@@ -94,16 +97,17 @@ public boolean updatePerson(Integer id, String firstName, String lastName, Strin
9497
}
9598

9699
public Integer deletePerson(Integer id) {
97-
SQLiteDatabase db = this.getWritableDatabase(DB_PASSWORD);
100+
SQLiteDatabase db = this.getWritableDatabase();
98101
return db.delete("person",
99102
"id = ? ",
100103
new String[]{Integer.toString(id)});
101104
}
102105

106+
@SuppressLint("Range")
103107
public ArrayList<String> getAllPerson() {
104108
ArrayList<String> arrayList = new ArrayList<>();
105109

106-
SQLiteDatabase db = this.getReadableDatabase(DB_PASSWORD);
110+
SQLiteDatabase db = this.getReadableDatabase();
107111
Cursor res = db.rawQuery("select * from person", null);
108112
res.moveToFirst();
109113

@@ -119,7 +123,7 @@ public ArrayList<String> getAllPerson() {
119123
}
120124

121125
public int count() {
122-
SQLiteDatabase db = getReadableDatabase(DB_PASSWORD);
126+
SQLiteDatabase db = getReadableDatabase();
123127
Cursor cursor = db.rawQuery("select * from person", null);
124128
try {
125129
if (cursor != null && cursor.getCount() > 0) {

0 commit comments

Comments
 (0)