The native SQLite engine included in the OS doesn't support encryption.
SQLCipher is an open source project that extends SQLite and adds full database encryption.
B4A SQLCipher object is a special subtype of SQL object. There is almost no need to change any code in order to switch from regular SQL to SQLCipher.
SQLCipher depends on a resource named icudt46l.zip. You should add this resource to the Files tab.
Preferably you should use a real device when developing as the emulator is too slow to handle the native resources.
The only difference between SQL API and SQLCipher API is the Initialize method.
SQLCipher.Initialize expects two additional values: Password and NativeLibsFolder.
Password is the database password. You can pass an empty string if there is no password. Note that it is not possible to change the password (or set a new password) to an existing database.
Code changes required to convert from SQL to SQLCipher
- Declare the SQL object as SQLCipher.
- Change the initialize code to:
ProgressDialogShow("Initializing database...")
SQL1.Initialize(File.DirRootExternal, "1.db", True, DB_PASSWORD, "")
ProgressDialogHide
Note that there is no need to change anything in DBUtils module.
The library can be downloaded here:
http://www.b4x.com/android/files/SQLCipher.zip
Another compiled library is available which is based on SQLCipher v3. Note that this library is not compatible with databases created with previous versions. You can download it here:
http://www.b4x.com/android/files/SQLCipher310.zip
Thank you @
hypergreatthing for sharing this.
Installation instructions:
- Unzip the file.
- Copy all files from the
InternalLibrariesFolder to the internal libraries folder.
- Add icudt46l.zip from the
NativeResources folder to your project as described above.
- You should reference both SQL and SQLCipher in your project.
- Starting from B4A v3.50 you need to disable the virtual assets folder (a new debugging feature). This is done by adding the following line to the main activity:
#DebuggerForceStandardAssets: true
v1.20 is now available. See this link: http://www.b4x.com/android/forum/th...th-sqlcipher-library.14965/page-4#post-207005