【问题标题】:Check if file is a valid SQLite database with SQLCipher encryption检查文件是否是使用 SQLCipher 加密的有效 SQLite 数据库
【发布时间】:2016-07-14 05:56:34
【问题描述】:

有什么方法可以在不知道加密密钥的情况下使用 SQLCipher 验证文件是否是有效的 SQLite 数据库?换言之,是否存在未加密的校验和或魔法词?

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

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

【问题讨论】:

    标签: sqlite encryption sqlcipher


    【解决方案1】:

    没有。 加密的数据库文件与包含随机数据的文件无法区分。

    【讨论】:

      【解决方案2】:

      我通过 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);
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2014-04-12
        • 1970-01-01
        • 2021-06-14
        • 2015-11-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-29
        • 1970-01-01
        相关资源
        最近更新 更多