Reputation: 627
I have worked with DBFlow which is quite simple to play around database but i want to ask is there a good example to use SQLCipher with DBFlow
I have Folowed this link for help
But if any one can provide some simple example will be very helpful to create secure database application with simple steps.
Upvotes: 5
Views: 1335
Reputation: 329
The usage doc linked by ConductedClever doesn't look like much but this is indeed almost all you need. Except for some details which could be mentioned:
I had to add @aar to the dbflow-cipher dependency in build.gradle to get it past gradle in the first place:
// build.gradle
def dbflow_version = "3.1.1"
def sqlcipher_version = "3.5.4"
dependencies {
annotationProcessor "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"
compile "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}"
compile "com.github.Raizlabs.DBFlow:dbflow:${dbflow_version}"
compile "com.github.Raizlabs.DBFlow:dbflow-sqlcipher:${dbflow_version}@aar"
compile "net.zetetic:android-database-sqlcipher:${sqlcipher_version}@aar"
}
Change the cipher secret as preferred:
// SQLCipherHelperImpl.java
public class SQLCipherHelperImpl extends SQLCipherOpenHelper {
public SQLCipherHelperImpl(DatabaseDefinition databaseDefinition, DatabaseHelperListener listener) {
super(databaseDefinition, listener);
}
@Override
protected String getCipherSecret() {
return "your-cipher-secret";
}
}
If you followed the dbflow getting started guide and your database is called AppDatabase then this is the class you should pass to new DatabaseConfig.Builder(AppDatabase.class)
when initializing DBFlow:
// AppDatabase.java
@Database(name = AppDatabase.NAME, version = AppDatabase.VERSION)
public class AppDatabase {
public static final String NAME = "AppDatabase";
public static final int VERSION = 1;
}
// DatabaseApplication.java
public class DatabaseApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
FlowManager.init(new FlowConfig.Builder(this)
.addDatabaseConfig(
new DatabaseConfig.Builder(AppDatabase.class)
.openHelper(new DatabaseConfig.OpenHelperCreator() {
@Override
public OpenHelper createHelper(DatabaseDefinition databaseDefinition, DatabaseHelperListener helperListener) {
return new SQLCipherHelperImpl(databaseDefinition, helperListener);
}
})
.build())
.build());
}
}
Export your database and try to open it in an SQLite Client. This should fail now cause of the encryption.
Upvotes: 6
Reputation: 4295
I haven't try it yet but this is the usage doc that the Official developer provides about using SQLcipher:
Upvotes: 0