Further to my previous post on encrypting App files I am following suggestions to put my Regex dictionaries into/out of encrypted SQLite files stored in my copy files.
I think I have been able to encrypt the files ok but can’t read them back. I have just been following the examples and have the following but can’t connect to the DB. Where could the issue be?
Var file As FolderItem = SpecialFolder.Resource("MyDictionary.sqlite")
If file <> Nil Then
mDBSQLite = New SQLiteDatabase
mDBSQLite.DatabaseFile = file
mDBSQLite.EncryptionKey = "aes256:5uper_2ecurePa55m0r9!"
If Not mDBSQLite.Connect Then
MessageBox("Error connecting to the database")
End If
Else
MessageBox("Error found while creating the file")
End If
mDBSQLite.Decrypt
SQLExtractData //extract the data and put back in Dictionaries
Did you check whether the file has the sqlite database in the resources folder?
e.g. set a break point and check manually in Finder to see if it is there.
Var file As FolderItem = SpecialFolder.Resources.Child("MyDictionary.sqlite")
If file <> Nil and file.Exists Then
mDBSQLite = New SQLiteDatabase
mDBSQLite.DatabaseFile = file
mDBSQLite.EncryptionKey = "aes256:5uper_2ecurePa55m0r9!"
If Not mDBSQLite.Connect Then
MessageBox("Error connecting to the database")
End If
Else
MessageBox("Error found while creating the file")
End If
// mDBSQLite.Decrypt
SQLExtractData //extract the data and put back in Dictionaries
I must admit, i’ve never seen that version of the syntax before.
I performed a quick check and both versions seem to point to the same path so either should have worked.
Var file As FolderItem = SpecialFolder.Resource("backup.sqlite")
Var file2 As FolderItem = SpecialFolder.Resources.Child("backup.sqlite")
If file.NativePath = file2.NativePath Then
Break
End If
Thanks Thomas, I removed the decrypt as suggested but rewrote a demo app which probably should have done from the start instead of trying to integrate it straight into the project but I now have it working
Maybe my final question on this one. If the only purpose I have for the SQLite database is for encrypting the data how do I remove it from memory once I have extracted the data?
Does mydb.close or mydb = nil remove an in-memory database altogether?
It will release it, not exacly erase it. Will become inaccessible to your app, but if you may be thinking about “will the contents vanish?” the answer is no, the memory garbage will be left in the memory. With right tools and a huge mem dump one could find “traces” of the contents. But it should be too much work for the average user. After the close and Nil you could allocate a big membloc and release it too, I guess Xojo nullify new blocks and with luck it will use the same released area by the DB erasing many traces.
One should put only read-only contents in the resources. If they want read-write, should copy the content stored in the resources to a proper read/write user space (folder) before working on it.