Android Tutorial Android database encryption with SQLCipher library

Status
Not open for further replies.
SQLCipher is an open source project that extends SQLite and adds full database encryption.
License: https://www.zetetic.net/sqlcipher/open-source/

B4A SQLCipher 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.

The only difference between SQL API and SQLCipher API is the Initialize method.
SQLCipher.Initialize expects two additional values: Password and a second parameter that is not used (it was used in the past).

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:
B4X:
SQL1.Initialize(File.DirRootExternal, "1.db", True, DB_PASSWORD, "")

V1.70
V1.60
V1.50
  • Based on SQLCipher v3.59
  • Supports targetSdkVersion 26.
  • The icu.zip file is no longer required. You can delete it from the Files folder.
  • It is no longer required to disable the debugger virtual assets feature.
    Remove this line: #DebuggerForceStandardAssets: True
  • Old version: www.b4x.com/android/files/SQLCipher150.zip

Depends on: https://repo1.maven.org/maven2/net/...er/4.5.4/android-database-sqlcipher-4.5.4.aar
You should download and copy it to the additional libraries folder.
 

Attachments

  • SQLCipher.zip
    37.2 KB · Views: 383
Last edited:

Taha

Member
Licensed User
Longtime User
Ok, now I understand. The library DOES create SQLCipher database. Checked that and it works! Thanks, Erel!
 

AscySoft

Active Member
Licensed User
Longtime User
I made a .net solution that uses multiple sqlite(normal) databases. If I'll switch to encryption on Android device, is there any possibilities on doing so on PC?
Is there any way to manipulate this SQLite encrypted database on normal PC?
 

CapReed

Member
Licensed User
Longtime User
Hi all,

I managed to run correctly with the emulator SQLCipher. I copied the files manually sqlcipher_native.zip unpacked to the folder "/ data / data / xxxxxxxx.yyyyy.zzzzz / files /" and then I copied the compressed file "sqlcipher_native.zip" in "/ mnt / sdcard / sqlcipher_native. zip "that is where I have stored the test database I created.

After that, everything works, great.

But now I want to do it in an automatic mode, that is, everything you need is inside the APK and only have to install the application from google play with everything you need.

Actually I have no idea how to do, how you could help me?

Thank you very much for your time.
 

Dexter438

New Member
I would love to use SQL-Cipher, but I'm worried that all somebody would have to do is unpack my .apk and easily find the password used to encrypt the database... wouldn't this be a pretty easy way to circumvent the db encryption?


Does anyone have any suggestions for hiding a password (within an Android app) that I could then use to encrypt the database with? I could of course obfuscate the password but this would only make the password slightly more tedious to detect.

I'm really just looking for a way to store data for my Android app that I absolutely don't want anybody messing with. Any suggestions would be extremely appreciated.
 

djpero

Member
Licensed User
Longtime User
My antivirus reporting a virus in this library jar file.
 

Attachments

  • virus.png
    virus.png
    9.7 KB · Views: 538

sioconcept

Active Member
Licensed User
Longtime User
I've add sqlcipher_native.zip to Files Tab and i've this error :

Compiling generated Java code. Error
javac 1.6.0_26
src\b4a\example\main.java:231: package a.b.test does not exist
public static a.b.test.SQLCipher _sqlc = null;

I've missing a step ?
 

djpero

Member
Licensed User
Longtime User
Just to make clear to myself and others:

- SQL cipher only create new database with ability of password
- you MUST include the sqlcipher_native in project under Files folder (that increasing the apk size plus 3,1Mb)

Am I right?

Is better way to encrypt all the data in db file? I found db files of other wellknown apps from market, they doing this: encryption of data, not ciphering.
 

Sinan Tuzcu

Well-Known Member
Licensed User
Longtime User
Helo,

i Need a example tutorial for this library.
can somebody help me

greet
sinan
 

coyote

Member
Licensed User
Longtime User
Hi,

I've already opened a thread in the german forum, but I've still no answer.

http://www.b4x.com/forum/german-forum/26636-urls-classes-dex.html)

So, let me ask my question again.

When I add the SQLCipher V.1.00 lib, compile the programm and open the classes.dex in notepad++, I see many URLs. See the picture below.

Why are so many URLs in the file? What are they use for?

Greetings, Coyote
 

Attachments

  • urls.PNG
    urls.PNG
    43.5 KB · Views: 727
Status
Not open for further replies.
Top