问题
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;
}
回答1:
Pointy Castle seems to be the encryption library of choice at the moment.
回答2:
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
回答3:
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.
来源:https://stackoverflow.com/questions/50232418/how-to-encrypt-the-sqlite-database-in-flutter