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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With