Sealite Driver
An SQLiteDriver whose every connection is SQLCipher-encrypted with a SealiteKey.
val driver = SealiteKey.raw(dek).use { SealiteDriver(it) } // closes the temporary key
dek.fill(0)
val db = Room.databaseBuilder<AppDatabase>(name = path).setDriver(driver).build()
// shutdown: db.close(), then driver.close()The driver keeps its own copy of key (Room opens pool connections lazily) and wipes it in close; the caller may close its own key right after construction. A connection is returned only after the key was applied and the database verified: a wrong key, a plaintext database, or a build that somehow linked a plain SQLite, fails open with a SealiteException (not an androidx.sqlite.SQLiteException); pass it (or the exception Room wraps it in) to Sealite.errorOf to get the SealiteError. Room's corruption recovery (allowDataLossOnRecovery) reacts only to SQLiteException, so it never deletes the database over a wrong key. Plain SQLite failures (I/O, a damaged page under the right key) stay SQLiteException.
A damaged file reports SealiteError.WRONG_KEY too, because an encrypted file is indistinguishable from random bytes: never delete the database yourself on WRONG_KEY.
Parameters
the key every connection is opened with; copied, so the caller may close its own.
how the file is read and written; the SQLCipher 4 defaults unless the file says otherwise.
Constructors
A driver with SealiteConfig.DEFAULT (SQLCipher 4).