sqlite-jdbc-crypt: Cannot open existing encrypted database

I have an encrypted SQLite database file written by another software that I want to read using this library. I know that my key is correct and that the file is valid because I can open it using DB Browser for SQLite. It is encrypted using SQLCipher 4 defaults and the key is 402fd482c38817c35ffa8ffb8c7d93143b749e7d315df7a81732a1ff43608497 (use passphrase mode in sqlite browser).

I tried opening it with this library using the following code:

String key = "402fd482c38817c35ffa8ffb8c7d93143b749e7d315df7a81732a1ff43608497";
String filePath = "/path/to/master.db";

String jdbcUrl = String.format("jdbc:sqlite:file:%s", filePath);

SQLiteMCConfig config = SQLiteMCSqlCipherConfig.getV4Defaults().withKey(key);

try (Connection connection = config.createConnection(jdbcUrl)) {
    System.out.println("Success!!");
}

But I keep getting:

org.sqlite.SQLiteException: [SQLITE_NOTADB]  File opened that is not a database file (file is not a database)
        at org.sqlite.core.DB.newSQLException(DB.java:1012) ~[sqlite-jdbc-3.33.0.1.jar:na]
        at org.sqlite.core.DB.newSQLException(DB.java:1024) ~[sqlite-jdbc-3.33.0.1.jar:na]
        at org.sqlite.core.DB.throwex(DB.java:989) ~[sqlite-jdbc-3.33.0.1.jar:na]
        at org.sqlite.core.NativeDB.prepare_utf8(Native Method) ~[sqlite-jdbc-3.33.0.1.jar:na]
        at org.sqlite.core.NativeDB.prepare(NativeDB.java:130) ~[sqlite-jdbc-3.33.0.1.jar:na]
        at org.sqlite.core.DB.prepare(DB.java:257) ~[sqlite-jdbc-3.33.0.1.jar:na]
        at org.sqlite.jdbc3.JDBC3Statement.execute(JDBC3Statement.java:45) ~[sqlite-jdbc-3.33.0.1.jar:na]
        at org.sqlite.SQLiteConfig.apply(SQLiteConfig.java:237) ~[sqlite-jdbc-3.33.0.1.jar:na]
        at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:65) ~[sqlite-jdbc-3.33.0.1.jar:na]
        at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:28) ~[sqlite-jdbc-3.33.0.1.jar:na]
        at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:21) ~[sqlite-jdbc-3.33.0.1.jar:na]
        at org.sqlite.JDBC.createConnection(JDBC.java:115) ~[sqlite-jdbc-3.33.0.1.jar:na]
        at org.sqlite.SQLiteConfig.createConnection(SQLiteConfig.java:102) ~[sqlite-jdbc-3.33.0.1.jar:na]

I have uploaded the database file in question so you can test and recreate the scenario for yourself: https://drive.google.com/file/d/1i-4lhdDDyUdDQ_pVvXpM2tfpaxH3SPhL/view?usp=sharing

Any help would be highly appreciated! 😃

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 20 (8 by maintainers)

Most upvoted comments

I’ll do some tests this week and I’ll come back to you.

Hi ! Sorry for the late reply. I still do not have the time to solve what i explained in #25 (comment)

Here are basically the build steps needed to build from scratch: …

Thank you. I will try to setup a local test environment.

Haven the same issue as @netmikey. Seem like we try to decrypt the same database. 😉

@Willena Is there any workaround available till the next release lands?

Sorry for the late answer, I am very busy for now, and don’t have a lot of time to give to this project. I have some issues with the native library that I need to solve first before creating a new release (see https://travis-ci.com/github/Willena/sqlite-jdbc-crypt).

For your information: these issues are related with AES Hardware acceleration in the native library. The built binary library ends up with a dependency on libcmusl that is of course not available on all machines (separate installation). I’d like to get rid of this dependency and stays with standard libc. I have to talk with the maintainer of the native library to see what is possible or not.

For your information: The bug has been reported and fixed in the native library. I’ll integrate the new version very soon.