Skip to content

sqlite-net-sqlcipher possible databasefile corruption #971

Open
@Widder2023

Description

@Widder2023

Dear Sir or Madames,

I am trying to build a xamarin application for android, ios and uwp with the sqlite-net-sqlcipher as database solution.
While starting/debugging the app for the first time, the database is created, the tables are created and I can insert records. After closing the application I cannot reopen the database. It always shows me the error like "file is not a database".

As Password I always use "test". As package I am using sqlite-net-sqlcipher 1.7.335 in combination with .net standard 2.1, tested on Android compiled with Android 10.0 Q and targeted API Level 29.

The Usage is like this:

public const SQLite.SQLiteOpenFlags Flags =
      // open the database in read/write mode
      SQLite.SQLiteOpenFlags.ReadWrite |
      // create the database if it doesn't exist
      SQLite.SQLiteOpenFlags.Create |
      // enable multi-threaded database access
      SQLite.SQLiteOpenFlags.SharedCache | SQLite.SQLiteOpenFlags.FullMutex;

  public CreateConnectionString(string dbPath, string password)
        {
            var sqloptions = new SQLiteConnectionString(dbPath, Flags, true,
 key: password,
                preKeyAction: (db) =>
                {
                    db.Execute("PRAGMA cipher_default_use_hmac = OFF;");              
                           db.Execute("PRAGMA cipher_page_size = 4096;");
                    db.Execute("PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA256;");
                    db.Execute("PRAGMA cipher_hmac_algorithm = HMAC_SHA256;");
                },
                postKeyAction: db => db.Execute("PRAGMA kdf_iter = 256000;"));
            DatabaseConnectionAsync = new SQLiteAsyncConnection(sqloptions);
}
}

or like this:

public CreateConnectionString(string dbPath, string password)
        {
            var sqloptions = new SQLiteConnectionString(dbPath, Flags, true,
key: password,
 preKeyAction: db => db.Execute("PRAGMA cipher_compatibility = 3;"));
            DatabaseConnectionAsync = new SQLiteAsyncConnection(sqloptions);
} }

What am I missing or what am I doing wrong? Or is it some kind of bug?

Kind regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions