maskarade/Android-Orma

Add encryption support

Closed this issue · 18 comments

Can Orma get encryption support in the future?
Integrate protect can get best experience for Orma (such as Realm, that support encryption on low level)

Lib for sql encryption
https://github.com/sqlcipher/android-database-sqlcipher

gfx commented

Currently I have no plan for encryption, but it might be in a future because the feature of changing SQLite engine is useful.

any news on this? would be great

does Android Orma use anything special/non standard? otherwise it should be easy to just switch to sqlcipher transparently

gfx commented

@zoff99 Not in progress but if someone needs I'll start working for it.

is this released already on maven? can i use it?

gfx commented

@zoff99 Not yet. Wait a minute!

gfx commented

Published Orma v5.0.0-rc1 to jcenter with encryption support, thanks to @k-kagurazaka (#402).

However, orma-encryption and orma-core are not linked to jcenter:

I have requested them to linked to jcenter, so it will be done in a day.

gfx commented

Now they are linked and become available via jcenter().

Please give it a try and issue feedbacks if something's wrong.

is there an example how to use this? it crashes on startup when i try it.

this works:

     OrmaDatabase.Builder builder = OrmaDatabase.builder(this);
     TrifaToxService.orma = builder.name(MAIN_DB_NAME).
       readOnMainThread(AccessThreadConstraint.WARNING).
       writeOnMainThread(AccessThreadConstraint.WARNING).
       build();

this crashes:

     OrmaDatabase.Builder builder = OrmaDatabase.builder(this);
     builder = builder.provider(new EncryptedDatabase.Provider("password"));
     TrifaToxService.orma = builder.name(MAIN_DB_NAME).
       readOnMainThread(AccessThreadConstraint.WARNING).
       writeOnMainThread(AccessThreadConstraint.WARNING).
       build();

@zoff99
Do you have a pre-existing database?
There are no compatibility between encrypted and un-encrypted database, so SQLCipher throw an exception when it try to open un-encrypted (SQLite's) database.

If no, please create a new issue with stack trace.

@k-kagurazaka no, cleared all data of the app.
is my syntax correct? do you have a working example?

Example app of Orma already uses encryption in encrypted flavor and it works.

gfx commented

@zoff99 It seems correct syntax.

Can you tell us more details?

  • Error messages including stacktraces
  • Android OS version

both on android 6.0 and 7.1
error 14 can not open database ...

will post more details later. dont have them now

Hmm... error 14 is a native error that occurred when SQLCipher failed to open database file.
Please check context.getDatabasePath(MAIN_DB_NAME) return a valid value.

does it have to be a full pathname? strange that it works without encryption

maybe sqlcipher native lib not loaded correctly?

thanks seems to work now. for some reason i have to delete the DB first.
but the DB should be removed if i clear all app data.
well, ok :-)