If I connect to a encrypted SQLite Databasefile without setting the encryption key first, then upon connection I’m getting an Errorcode 21 with this message: “LIBRARY ROUTINE CALLED OUT OF SEQUENCE”.
I wonder if there is a reliable way to catch errors and then have a meaningful message displayed to the user (the one above is not).
If mDB.Connect Then
mDB.Decrypt
mIsConnected = True
MsgBox(“SQLite database connected.”)
Else
mDB.EncryptionKey =""
If mDB.Connect Then
mDB.Decrypt
mIsConnected = True
MsgBox (“SQLite database connected and not crypted.”)
else
mIsConnected = False
MsgBox ("Error connecting SQLite database: " + mDb.ErrorMessage)
mDB.Encrypt (“mykey+to+crypt”)
mDB.Close
End If
End If
If Not IsConnected Then
MsgBox(“Create the database first, the table and add the data.”)
End If
Cypher_Key=""
db.EncryptionKey=Cypher_Key
If DB.Connect=False Then
If db.ErrorCode=21 Or db.errorcode=26 Then' File is encrypted or is not a database
//
Do
Cypher_Key=Get_db_Password(False) ' ask user for key
If Cypher_Key="" Then 'user gave up
Quit
Return
End If
db.EncryptionKey=Cypher_Key
If db.Connect Then Exit Do
Loop
//
Else
msgbox "connection error"
Quit
End If
End If
@Valdemar De SOUSA - there’s no reason to Decrypt the database. I would leave it encrypted on disk. Your app will be able to read it, because you have supplied the encryption key, but nobody else will be able to read it. If you decrypt it during the execution of your app, then it is available to anyone for the duration of your program. And if your app crashes, you would leave it unencrypted on disk.
Right Tim, in my case I want that the database stay decrypted until the end of the App. But in other case, to let the database encrypt just remove the ‘mDB.Decrypt’ lines.