Android Question Mostly solved:Encryption Initialization Creation

Shelby

Well-Known Member
Licensed User
My problem is that my project will no longer compile now that I have attempted to use SQLCipher invented by Zetetic.net.

On a tutorial by Erel,(https://www.b4x.com/android/forum/t...ryption-with-sqlcipher-library.14965/#content), Erel tells me to use the following line to initialize the SQLCipher method.

SQL1.Initialize(File.DirRootExternal, "1.db", True, DB_PASSWORD, ""):

Unfortunately, the IDE slips me the note; Undeclared variable 'SQL1' is used before it was assigned any value.

In actuality I don't have a variable SQL1 anyway, so how shall I change the wording to make it work for my project. I'll attach a screenshot of when the compilation goes haywire.... Whoops, the image was too large. Here's the wetransfer.com link:
https://we.tl/t-vXVH78nqBw

Of course my project is an SQLite one. It has 712 records
 
Solution
Your Additional Libraries path is this (see red border)
微信图片_20240630020631.png

but you put android-database-sqlcipher-4.5.4.aar into project folder not Additional folder
微信图片_20240630020722.png

You should put the android-database-sqlcipher-4.5.4.aar into folder C:\Users\HP\Desktop\Projects\Additional Libraries\B4A

微信图片_20240630021452.png

Shelby

Well-Known Member
Licensed User
Now my error is in these lines :
error:
B4XPages.SetTitle(Me, "SS2021B4X")
    If sql.IsInitialized = False Then
        Try
            #If B4J
            sql.InitializeSQLite(DBFileDir, DBFileName,True)
            #Else
            sql.Initialize(DBFileDir, DBFileName,True)
            #End If

It's telling me a comma was expected somewhere in this line:
sql.Initialize(DBFileDir, DBFileName,True)
Db file name as string (global variable (that's on line 85)
 
Upvote 0

Shelby

Well-Known Member
Licensed User
The signature is error, it should be this
B4X:
SQL1.Initialize(DBFileDir, DBFileName, True, DB_PASSWORD, "")
Thanks Ted, I used that (after taking out the numeral 1)
Now I still get the line 86 problem with this line:
sql.Initialize(DBFileDir, DBFileName,True)

Maybe I should write SQLCipher at the beginning of that line....Nope, didn't work; still has that expected comma comment when I hover over squiggly line.
Also this in Class-Globals:
B4X:
Public DBFileName = "dbircV11.db" As String
DBFileName is greened out everywhere (hovering, it doesn't like As string?)
 
Last edited:
Upvote 0

teddybear

Well-Known Member
Licensed User
Thanks Ted, I used that (after taking out the numeral 1)
Now I still get the line 86 problem with this line:
sql.Initialize(DBFileDir, DBFileName,True)

Maybe I should write SQLCipher at the beginning of that line....Nope, didn't work; still has that expected comma comment when I hover over squiggly line.
Also this in Class-Globals:
B4X:
Public DBFileName = "dbircV11.db" As String
DBFileName is greened out everywhere (hovering, it doesn't like string?)
微信图片_20240629234607.png

Do you do sql1.initialize like this?
At the line 86, is it sql.Initialize(DBFileDir, DBFileName,True)?
 
Upvote 1

Shelby

Well-Known Member
Licensed User
View attachment 155007
Do you do sql1.initialize like this?
At the line 86, is it sql.Initialize(DBFileDir, DBFileName,True)?
yes
B4X:
B4XPages.SetTitle(Me, "SS2021B4X")
    If sql.IsInitialized = False Then
        Try
            #If B4J
86            sql.InitializeSQLite(DBFileDir, DBFileName,True)
            #Else
            sql.Initialize(DBFileDir, DBFileName,True)
            #End If

I noticed mine is slightly different.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
That expected comma comment, it should be missing some parameters.
it also should be sql.Initialize(DBFileDir, DBFileName,True, "", "") instead of sql.Initialize(DBFileDir, DBFileName,True)
when you hover over line 86. it looks like the pic which I posted #7
 
Upvote 0

Shelby

Well-Known Member
Licensed User
OK
But I'm not clear on needed parameters
I changed the line and it appears to be better (no squiggly line)

Next error I'll have to work on:

B4A Version: 12.80
Parsing code. (0.11s)
Java Version: 14
Building folders structure. (0.02s)
Running custom action. (0.27s)
Compiling code. (0.13s)
Compiling layouts code. (0.05s)
Organizing libraries. Error
Could not find file 'C:\Program Files\Anywhere Software\B4A\libraries\android-database-sqlcipher-4.5.4.aar'.


I'm apparently getting very close now. Thanks Teddy
 
Last edited:
Upvote 0

teddybear

Well-Known Member
Licensed User
OK
But I'm not clear on needed parameters
I changed the line and it appears to be better (no squiggly line)

Next error I'll have to work on:

Could not find file 'C:\Program Files\Anywhere Software\B4A\libraries\android-database-sqlcipher-4.5.4.aar'.
You are missing android-database-sqlcipher-4.5.4.aar. download it and the copy it to additional folder.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
But I'm not clear on needed parameters
You need to declare a variable DB_PASSWORD in Class_Globals
Class_Globals:
Private DB_PASSWORD As String = "CrankKid"

Then you don't need to replace the password which you mistakenly put in the Unused parameter:
B4X:
sql.Initialize(DBFileDir, DBFileName, True, DB_PASSWORD, "")
 
Upvote 0

Shelby

Well-Known Member
Licensed User
Still I get the error:
Could not find file 'C:\Program Files\Anywhere Software\B4A\libraries\android-database-sqlcipher-4.5.4.aar'.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Still I get the error:
Could not find file 'C:\Program Files\Anywhere Software\B4A\libraries\android-database-sqlcipher-4.5.4.aar'.
Did you download the file and move it to additional libraries folder?
 
Upvote 0

Shelby

Well-Known Member
Licensed User
I think I have that:

B4X:
Class_Globals
    Private Root As B4XView
    Private xui As XUI
  
    Public sql As SQLCipher
    Private db_password  As  String
        Public DBFileDir As String
    Public DBFileName = "dbircV11.db" As String
    Public Shared As String
    Public ImageFileName As String
  
    Private xtblItems As xTableLite
    Private ZoomImageView1 As ZoomImageView
    Private btnQuit As Button
#If B4A
    Public rp As RuntimePermissions
#End If
    Private lblTitle As B4XView
    Private lblSearch As B4XView           'first use of word: 'search'
    Private lblCancel As B4XView
    Private edtSearch As B4XView
    Private xTableSearch As xTableLite
    Private writing As Boolean            'Boolean to wait for search while writing
    Private timerSearch As Timer    'The timer that will check when is possible to start Search
    Private SearchPattern As String        'Variable to Hold the pattern to search for
    Private lstSearch As List            'List contains copy of DB to fasten the search (I suppose)
    Private ime As IME                    'Library to handle the keyboard and hide it when no longer needed
End Sub
Did you download the file and move it to additional libraries folder?
When I clicked yours above it downloaded; I put into the additional library folder and the anywhere
 
Upvote 0
Top