Windows Phone 8的SQLCipher无法加密设备上的纯文本数据库,然后对其进行查询

时间:2014-03-18 16:08:22

标签: sqlite windows-phone-8 sqlcipher

目前是否有人在使用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();
        }

1 个答案:

答案 0 :(得分:0)

此问题已得到解决,它与本地用户设置有关,而不是SQLCipher的问题。可以找到解决方案的详细信息here