9

I am creating a database in Flutter by the following code, is there any way we can encrypt the database?

Is there any library available for Flutter?

initDb() async {
    io.Directory documentsDirectory = await getApplicationDocumentsDirectory();
    String path = join(documentsDirectory.path, "test.db");
    var theDb = await openDatabase(path, version: 1, onCreate: _onCreate);
    return theDb;
  }
Kromster
  • 7,181
  • 7
  • 63
  • 111
Raja Jawahar
  • 6,742
  • 9
  • 45
  • 56

3 Answers3

6

Pointy Castle seems to be the encryption library of choice at the moment.

Randal Schwartz
  • 39,428
  • 4
  • 43
  • 70
1

Current sqflite uses whatever sqlite version the platform provides. There is a discussion about that here that you could follow here: https://github.com/tekartik/sqflite/issues/32

The only solution I am aware now is this one https://github.com/QwilApp/encrypted_sqlite which can be used as a drop-in replacement to sqflite which as you stated uses SQLCipher on the native side

alextk
  • 5,713
  • 21
  • 34
  • 2
    Hi, @alextk You might want to update this answer with your library https://pub.dev/packages/sembast Thanks! :) – DazChong Jul 12 '19 at 03:24
  • @DazChong well the question was about encrypting sqlite database, sembast is an alternative but it ain't no sql! – alextk Jul 12 '19 at 17:52
1

I am also looking for such a library today.

And finally I found flutter_sqlcipher in pub.dev, which really solved my problem.

Here is the description of it.

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.

Hope it helps you.

NeroSong
  • 11
  • 3
  • 1
    Caveat: _Android only, at present. (iOS support is planned.)_ [Source](https://pub.dev/packages/flutter_sqlcipher#compatibility) – lo2ndii Aug 24 '20 at 14:00