检查文件是否是带有SQLCipher加密的有效SQLite数据库

问题描述 投票:0回答:2

有没有办法在不知道加密密钥的情况下用SQLCipher验证文件是否是有效的SQLite数据库?换句话说,有没有加密的校验和或魔术字?

this post我理解正常的SQLite 3数据库只是以字符串“sqlite 3”开头,如果我知道密码,我可以检查实际高级数据库结构using this的有效性。

错误消息“文件已加密或不是数据库”found here表明答案是否定的 - 但任何人都可以确认?

sqlite encryption sqlcipher
2个回答
2
投票

不可以。加密的数据库文件与包含随机数据的文件无法区分。


0
投票

我在DBHelper的构造函数中通过此代码解决(它不是纯净的,但它可以工作......)

private DBHelper() {
    SQLiteDatabase.loadLibs(context);

    File dbFile = context.getDatabasePath(DB_NAME);

    try {
        if (dbFile.exists()) { // is db file exists?
            // check if db file can be opened
            SQLiteDatabase.openDatabase(dbFile.getAbsolutePath(), DB_PASSWORD, null, SQLiteDatabase.OPEN_READWRITE).close();
        }
    } catch (SQLiteException ex) { // it's impossible open db file - we must encrypt it
        encryptDatabase(context, dbFile);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.