目前是否有人在使用SqlCipher的Windows Phone 8上执行此操作?我在他们的GitHub板上与他们进行了沟通,但是我现在还没有解决方案 - 这就是一个例子:
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();
}
}
没有由此产生的文件,可能是预期的,也没有抛出异常:
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();
}
这也在指定点失败:
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();
}