This issue has been resolved, it was related to a local user setup, not an issue with SQLCipher. Details of the resolution can be found here.
SQLCipher with Windows Phone 8 unable to encrypt a plain text database on device and then query it
-
16-06-2023 - |
Question
Is anyone currently doing this on Windows Phone 8 with SqlCipher? I'm communicating with them on their GitHub board, but I'm down to the wire without a solution at this point - here's an example:
public void Encrypt(string newpassword) {
string encryptedDb = _dbConnection + "_";
File.Delete(encryptedDb);
using (var db = new SQLiteConnection(_dbConnection, _dbPassword)) {
//attachResult == 0
int attachResult = db.Execute(string.Format("ATTACH DATABASE '{0}' AS encrypted KEY '{1}'", encryptedDb, newpassword));
//exportResult == null
string exportResult = db.ExecuteScalar<String>("select sqlcipher_export('encrypted')");
//detachResult == 0
int detachResult = db.Execute("DETACH DATABASE encrypted");
db.Close();
}
//confirmed in storage 2 files db.s3db (unencrypted 25.0K) and db.s3db_(encrupted 27.0K)
File.Copy(encryptedDb, _dbConnection, true);
File.Delete(encryptedDb);
//one remaining file db.s3db (encrypted with 'newpassword')
using (var db = new SQLiteConnection(_dbConnection, newpassword)) {
//throws "file is not a database or is encrypted"
int records = db.ExecuteScalar<int>("select count(*) from sqlite_master;");
db.Close();
}
}
No file produced by this, maybe that's expected and no exceptions thrown:
using (var db = new SQLiteConnection(_dbConnection, "")) {
int attachResult = db.Execute("ATTACH DATABASE 'plaintext.db' AS plaintext KEY ''");
string exportResult = db.ExecuteScalar<String>("SELECT sqlcipher_export('plaintext')");
int detachResult = db.Execute("DETACH DATABASE plaintext");
db.Close();
}
This also fails at the indicated point:
using (var db = new SQLiteConnection(_dbConnection, "")) {
//attachResult == 0
int attachResult = db.Execute(string.Format("ATTACH DATABASE '{0}' AS encrypted KEY '{1}'", encryptedDb, "12345"));
//exportResult == null
string exportResult = db.ExecuteScalar<String>("select sqlcipher_export('encrypted')");
//detachResult == 0
int detachResult = db.Execute("DETACH DATABASE encrypted");
db.Close();
}
using (var db = new SQLiteConnection(encryptedDb, "12345")) {
//fails - 'Non db'
int attachResult = db.Execute("ATTACH DATABASE 'plaintext.db' AS plaintext KEY ''");
string exportResult = db.ExecuteScalar<String>("SELECT sqlcipher_export('plaintext')");
int detachResult = db.Execute("DETACH DATABASE plaintext");
db.Close();
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow