0

How do we achieve encryption using the Android Room library. I found this library:

https://github.com/commonsguy/cwac-saferoom

However, I can't find a complete example as to how to implement Room with CWAC-Saferoom for encryption purposes. Also

  1. Does the CWAC-Saferoom use 512 bit encryption key for the database?
  2. And how is the database encrypted itself?

Are there any other alternatives that i can use for encrypting database on Android which use maybe 512/1024 bit encryption?

user2511882
  • 9,022
  • 10
  • 51
  • 59

1 Answers1

1

However, I can't find a complete example as to how to implement Room with CWAC-Saferoom for encryption purposes

There is a demo/ app in the project.

Does the CWAC-Saferoom use 512 bit encryption key for the database?

CWAC-SafeRoom does not perform encryption. Its classes connect Room with SQLCipher for Android, a version of SQLite that offers transparent encryption of its contents. Please consult the SQLCipher documentation for questions about SQLCipher.

And how is the database encrypted itself?

This is covered in the SQLCipher documentation.

Are there any other alternatives that i can use for encrypting database on Android which use maybe 512/1024 bit encryption?

Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I went through the demo app in the project. However, I am not able to decipher what kind of encryption key is used on the note.db. Is there a sample app which doesn't use Rx that you can point me to? – user2511882 Mar 26 '19 at 14:24
  • @user2511882: "However, I am not able to decipher what kind of encryption key is used on the note.db" -- that sample app generates an passphrase that is then encrypted using hardware encryption. The passphrase itself is passed through SafeRoom to SQLCipher, which runs it through a bunch of PBKDF2 rounds and uses the result for the actual key. "Is there a sample app which doesn't use Rx that you can point me to?" -- I don't have one handy, sorry. You are certainly welcome to pass whatever passphrase you want, via a `char[]` or an `Editable` (e.g., from an `EditText`). – CommonsWare Mar 26 '19 at 14:43
  • @user2511882: But the actual "encryption key" is the result of those PBKDF2 rounds. Where the passphrase is from does not matter to SQLCipher or to SafeRoom. – CommonsWare Mar 26 '19 at 14:45
  • @CommonsWare ,hi when i remove my app from task bar , i cant access to my encrypted data base and app crash with this : SQLiteDatabaseCorruptException: file is encrypted or is not a database – milad salimi Jun 16 '19 at 11:43
  • @miladsalimi: That is a very generic error message. It can come from lots of things, though the most common cause is from having the wrong passphrase. Perhaps you need to ask the user for their passphrase again. If you have additional concerns, please ask a fresh Stack Overflow question where you provide a [mcve]. – CommonsWare Jun 16 '19 at 11:47
  • @CommonsWare , i have a problem about room . please check [link](https://stackoverflow.com/questions/56628647/android-room-database-file-is-invalid-file-format-in-db-browser) – milad salimi Jun 17 '19 at 10:48