'SQLite Encrypted Database cannot be opened in DB Browser

I have written a small test program with which I create and encrypt a SQLite DB created using Java sqlite-jdbc.

a) Unfortunately I can't access the encrypted DB file with SQLite DB Browser resp.

b) I can't read a database encrypted with the DB Browser via SQlite.

I try to set the same configurations for both variants.

public class EncryptDB {

private static final Logger log = LogManager.getLogger(EncryptDB.class);
private final static String DATABASE = "jdbc:sqlite:file:Test.db";
private final static String DB_PASS = "test22";

public static void main(String[] args) {

log.debug("EncryptDB gestartet");
try {
     Connection conn = DriverManager.getConnection(DATABASE);
        
     SQLiteMCSqlCipherConfig config = new SQLiteMCSqlCipherConfig();
     config.setUserVersion(4);
     config.setKdfIter(256000);
     config.setFastKdfIter(2);
     config.setHmacPgno(HmacPgno.NATIVE);
     config.setHmacSaltMask(58);
     config.setLegacy(4);
     config.setLegacyPageSize(4096);
     config.setKdfAlgorithm(KdfAlgorithm.SHA512);
     config.setHmacAlgorithm(HmacAlgorithm.SHA512);
     config.setPlaintextHeaderSize(0);
     config.setCipher(CipherAlgorithm.SQL_CIPHER);
     config.setHmacUse(false);
     config.enforceForeignKeys(true);
     config.withKey(DB_PASS);
     conn.setAutoCommit(false);
             
     conn = DriverManager.getConnection(DATABASE,config.toProperties());
     
    
     
     String sql = "CREATE TABLE IF NOT EXISTS \"Test\" (\r\n"
            + " \"ID\"  INTEGER NOT NULL UNIQUE,\r\n"
            + " \"Name\"    INTEGER,\r\n"
            + " PRIMARY KEY(\"ID\" AUTOINCREMENT)\r\n"
            + ")";
     Statement stmt  = conn.createStatement();
     boolean rs    = stmt.execute(sql); 
     
     sql = "INSERT INTO \"Test\" (Name) Values ('Tom')";
     stmt  = conn.createStatement();
     rs    = stmt.execute(sql);
     
     sql = "SELECT * From Test";
     stmt  = conn.createStatement();
     ResultSet rs1 = stmt.executeQuery(sql);
     
     while (rs1.next()) {
         log.debug("Result: "+rs1.getString(1));                 
     }           
     conn.close();   
} catch (SQLException e) {
    e.printStackTrace();
}               

}

I use the:

  • SQLite DB Browser 3.12.2 (version for SQLCipher)

  • sqlite-jdbc-3.37.2.jar

enter image description here

ad a) password input in DB Browser does not accept the password

ad b) I get the error message: [SQLITE_NOTADB] File opened that is not a database file (file is not a database)

Is there a solution for this or are the two crypt mechanisms completely incompatible.

Thanks GGK



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source