native_sqlcipher
Encrypted SQLite databases for DartNative, powered by SQLCipher 4.10.0. Supports iOS and Android.
Install
Add to your DartNative app's pubspec.yaml:
dependencies:
native_sqlcipher:
hosted: https://dartpub.dev
version: ^0.1.1
Run dn pub get, then rebuild the app to link the native plugin. Use the generated plugin registrant provided by your DartNative app template.
Use
import 'dart:typed_data';
import 'package:native_sqlcipher/native_sqlcipher.dart';
// Supply a writable path and a passphrase from your secure storage.
void saveNote(String databasePath, Uint8List passphrase) {
final db = SqlCipherDatabase.open(
databasePath,
key: passphrase,
create: true,
);
try {
db.execute('CREATE TABLE IF NOT EXISTS notes (body TEXT NOT NULL)');
db.execute('INSERT INTO notes (body) VALUES (?)', ['Hello']);
final notes = db.select('SELECT body FROM notes');
print(notes);
} finally {
db.close();
}
}
Notes
- Passphrase bytes are used to derive the encryption key. Keep them in secure storage; do not hardcode them.
- Opening an existing database is the default. Use
create: trueonly when creating one is intended. Wrong keys throwSqlCipherException. - Queries and transactions are synchronous. Use a worker isolate for longer operations, and keep transaction callbacks synchronous.
- Native targets require iOS 15+ or Android API 26+. Your DartNative SDK may require a newer OS.
Supports bound parameters, transactions, nested savepoints, and SQLite schema versions. See API notes for details and native linking requirements.
MIT license. SQLCipher has a separate BSD license.