Android Question Problem Using SQLCipher

jotajota52

Member
Hi!
I'm trying to open an sqlite database that has been encrypted using SQLCipher 4, and I can open it using the correct passphrase using DB Browser (SQLCipher version)
But in B4A is not working
This is an example of what I'm doing, using SQLCipher library version 1.60

Sub Process_Globals
Private sql As SQLCipher
End Sub

Later on, having chosen de database file:

sql.Initialize(File.DirInternal,mydatabase,False,"12345","")

and this errors out as:

net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;

Is there any way to config the SQLCipher lib to open it using SQLCipher 4 defaults?

George.
 

jotajota52

Member
Thank you Erel,
While doing more testing I found out that using an alphanumeric password, such as "Abc1234" is the problem here
If the database has a numeric password (all numbers) the B4A SQLCipher v1.60 works just fine.

This works:
(mydatabase1 has been encrypted with a numeric password. I can open it in my desktop)

B4X:
Dim passw As String ="1234567"
 sql.Initialize(File.DirInternal,mydatabase1,False,passw,"")


This throws an error:
(mydatabase2 has been encrypted with a alphanumeric password. Again, I can open it in my desktop.)

B4X:
Dim passw As String ="Abc1234567"
 sql.Initialize(File.DirInternal,mydatabase2,False,passw,"")

What would be the correct way to pass it an alphanumeric password to the sql.initialize ??
George.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Thank you Erel,
While doing more testing I found out that using an alphanumeric password, such as "Abc1234" is the problem here
If the database has a numeric password (all numbers) the B4A SQLCipher v1.60 works just fine.

This works:
(mydatabase1 has been encrypted with a numeric password. I can open it in my desktop)

B4X:
Dim passw As String ="1234567"
sql.Initialize(File.DirInternal,mydatabase1,False,passw,"")


This throws an error:
(mydatabase2 has been encrypted with a alphanumeric password. Again, I can open it in my desktop.)

B4X:
Dim passw As String ="Abc1234567"
sql.Initialize(File.DirInternal,mydatabase2,False,passw,"")

What would be the correct way to pass it an alphanumeric password to the sql.initialize ??
George.
I am using B4A SQLCipher with a password Abc_1234 and it works fine.
What you can do is create a new DB with an alphanumeric password and check if it works for you.
 
Upvote 0

Apip Bayok

Member
Use SQLCipher with V1.60 lib, dependsOn android-database-sqlcipher-4.1.2.aar and it's works fine with alphanumeric password.
B4X:
Sub Process_Globals
    Dim SQLC As SQLCipher
    Private RP As RuntimePermissions
    Private SafeDirectory As String
End Sub

Sub OpenDBF
    SafeDirectory = RP.GetSafeDirDefaultExternal("")
    SQLC.Initialize(SafeDirectory, "gg.db", True, "jogang8310", "")
End Sub

in XML file
B4X:
<dependsOn>android-database-sqlcipher-4.1.2.aar</dependsOn>
 
Upvote 0

jotajota52

Member
Thank you again Erel and Alex. I think the problem then might be my desktop app when I cipher
I use my connection object to establish the defaults and the key
B4X:
sCnn.CodecType = CODEC_TYPE_SQLCIPHER
sCnn.Execute "PRAGMA legacy=4;"
sCnn.Execute "PRAGMA key='" & "Abc1234" & "';"
Note that the key is a string and I pass it with single quotes to make sure it goes as string.
I can then use any app (such as DB Browser for SQLite) to open the database with that passphrase
I'll be doing some more testing.
 
Upvote 0
Top