SQLCipher Database for Flutter

Project license Pub package Dartdoc reference Travis CI build status

This is a Flutter plugin that bundles and wraps SQLCipher for Android, an open-source extension to SQLite that provides transparent 256-bit AES encryption of database files.

Features

  • Implements fully-encrypted SQLite databases stored on disk or in memory.

  • Provides a high-fidelity subset of the android.database.sqlite API to aid Android developers migrating to Flutter.

  • Supports booleans, doubles, integers, strings, blobs, and timestamps.

Compatibility

Android only, at present. (iOS support is planned.)

Examples

Querying an in-memory database

This example also uses DatabaseUtils from the flutter_android package.

import 'package:flutter_sqlcipher/sqlite.dart';
import 'package:flutter_android/android_database.dart' show DatabaseUtils;

var db = await SQLiteDatabase.createInMemory();

var cursor = await db.rawQuery("SELECT 1 AS a, 2 as b, 3 AS c");

await DatabaseUtils.dumpCursor(cursor);

Frequently Asked Questions

Which releases of SQLite and SQLCipher does this plugin bundle?

SQLCipher for Android 4.0.0, SQLCipher 4.0.0, and SQLite 3.25.2.

Why this plugin instead of wrapping Android's native SQLite support?

Two good reasons are:

  1. Encryption. Android's native SQLite support does not feature database encryption. By using this plugin, you can trivially enable encryption for your app database, something likely appreciated by both you as well as your users.

  2. Compatibility. Android's native SQLite version varies greatly depending on the specific Android release, from SQLite 3.4 (released in 2007) to SQLite 3.19 (released in 2017, bundled in Android 8.1). Further, some device manufacturers include different versions of SQLite on their devices. By using this plugin, you gain a consistent, predictable, and up-to-date version of SQLite for your app regardless of the Android release your app runs on.

How much does using this plugin increase my final app size?

Due to the bundled SQLCipher native libraries, your final APK size currently increases by about 6.7 MiB. We are actively investigating ways to reduce that footprint. (e.g., pruning .so files and using ProGuard).

Some of the android.database.sqlite API methods are missing?

We don't generally implement methods deprecated in the current Android API level. For example, the SQLiteDatabase#isDbLockedByOtherThreads() method was deprecated long ago (in Android 4.1), so we have omitted it from the Dart interface when implementing this plugin.

Caveats

  • At present, iOS is not supported. This may eventually be addressed going forward by bundling and wrapping FMDB which includes SQLCipher support.

  • At present, cursors are fully materialized. This means that queries which return very large result sets will incur nontrivial overhead in the IPC transfer of the cursor data from Java to Dart. We are planning on adding windowed cursor and streaming support in a future major release. In the meanwhile, OFFSET and LIMIT are your friends.

Reference

sqlite

import 'package:flutter_sqlcipher/sqlite.dart';

sqlcipher

import 'package:flutter_sqlcipher/sqlcipher.dart';

See Also

  • The sql_builder package that implements a fluent interface for constructing SQL queries.

Libraries

sqlcipher
SQLCipher interface. [...]
sqlite
SQLite interface. [...]