How to read an encrypted database created previously on pc with sqlcipher on android?

时光总嘲笑我的痴心妄想 提交于 2019-12-07 13:49:27

问题


I'm trying to read an encrypted database created with sqlcipher on my PC but I can't read it on my app. For example:

Cursor c = database.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
    c.moveToFirst();
    do {
        String s = c.getString(0);
        if (s.equals("android_metadata")) {
            // System.out.println("Get Metadata");
            continue;
        } else {
            dirArray.add(s);
        }
    } while (c.moveToNext());
    Log.i("getS", "DATABASE = " + dirArray.toString());
    Log.i("getS", "length = " + dirArray.size());

result on the following

03-12 03:28:12.691: I/getS(9895): DATABASE = []
03-12 03:28:12.691: I/getS(9895): length = 0

also this:

Cursor c2 = database.query("my_table", new String[] { "name" }, null, null, null, null, "name");

return in to this:

03-12 03:28:12.701: I/Database(9895): sqlite returned: error code = 1, msg = no such table: my_table

I'm compiling with sdk-7, if I try the same database unencrypted and without the sqlcipher, I don't have any problems. Could anyone teach me how do I read on android a database encrypted on my computer? Appreciate ;)


回答1:


You will want to use the SQLCipher for Android library which will allow you to access and modify a sqlcipher database on an Android device. We currently support Android 2.1 - 4.0.3. Binary downloads can be found here:

https://github.com/sqlcipher/android-database-sqlcipher/downloads

A tutorial on itegrating SQLCipher for Android can be found here:

http://sqlcipher.net/sqlcipher-for-android/



来源:https://stackoverflow.com/questions/9676905/how-to-read-an-encrypted-database-created-previously-on-pc-with-sqlcipher-on-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!