Hi all you SQLCipher experts - hoping you can help me.
I’m working on a Windows 10 UWP app using Visual Studio 2017. We need to use SQLCipher to store user documents in an encrypted format but I am running into issues that I can’t find any answer for. As the tile says I am new to SQLite so I found a blog that showed me how to get going with SQLCipher to create an encrypted db - the code below uses Eric Sink’s SQLitePCLRaw library as that was the only thing I could get working
private void CreateSQLCipherDB()
{
const string key = "#a1b2c3d4#";
string query = null;
string dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "testdb.sqlite");
SQLitePCL.sqlite3 sqlite3 = null;
var sqlProvider = new SQLitePCL.SQLite3Provider_sqlcipher();
SQLitePCL.raw.SetProvider(sqlProvider);
try
{
SQLitePCL.raw.sqlite3_open(dbPath, out sqlite3)
query = $"PRAGMA key = '{key}'";
SQLitePCL.raw.sqlite3_exec(sqlite3, query)
query = $"CREATE TABLE Table1 (id INTEGER PRIMARY KEY NOT NULL, message TEXT);";
SQLitePCL.raw.sqlite3_exec(sqlite3, query)
query = $"INSERT INTO Table1 VALUES(NULL, 'David Bowie');";
SQLitePCL.raw.sqlite3_exec(sqlite3, query)
query = $"INSERT INTO Table1 VALUES(NULL, 'Nina Simone');";
SQLitePCL.raw.sqlite3_exec(sqlite3, query)
}
catch(Exception ex)
{
SQLitePCL.raw.sqlite3_close(sqlite3);
}
}
So this code works fine and creates what I believe is an encrypted database… the problem is how to then read values back out of the database. I have the code below but I honestly have no idea what to do after the “int rows = SQLitePCL.raw.sqlite3_exec(sqlite3, query);” line to get my data into a List and I can’t seem to find any reference to the raw PCL commands (using C#) that I need.
private void QuerySQLCipherDB()
{
const string key = "#a1b2c3d4#";
string dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "testdb.sqlite");
SQLitePCL.sqlite3 sqlite3 = null;
var sqlProvider = new SQLitePCL.SQLite3Provider_sqlcipher();
SQLitePCL.raw.SetProvider(sqlProvider);
SQLitePCL.raw.sqlite3_open(dbPath, out sqlite3);
try
{
query = $"PRAGMA key = '{key}'";
var query = "SELECT id,message FROM Table1";
int rows = SQLitePCL.raw.sqlite3_exec(sqlite3, query);
//How do I get the above data into a useful collection object?
}
catch (Exception ex)
{
SQLitePCL.raw.sqlite3_close(sqlite3);
}
}
So can anyone point me in the right direction please? I know it’s probably stupidly simple but I’ve searched google and read forums until I’m blue in the face but can’t seem to find decent documentation or examples for using the raw SQLite commands in C#.
TIA for any help offered