useEncryptionKey method
Opens the application database with key from now on (null: no
key). The database currently open is closed; the next access reopens
it.
- A new database is created encrypted (SQLite3MultipleCiphers).
- An existing encrypted database opens only with its key; a wrong key throws a StateError.
- An existing unencrypted database is refused with a StateError: call encryptDatabase to encrypt it in place.
- The engine is checked first: if it does not encrypt, opening throws
a StateError explaining what to add to the application's
pubspec.yaml. A database is never created in plaintext by mistake.
On Android and iOS an encrypted database goes through the SQLite
bundled by package:sqlite3, not the system one. The key is never
stored by b012_data: the application provides it at each start. Files
saved by name with DiscData are encrypted too (AES-256-GCM).
Implementation
Future<void> useEncryptionKey(String? key) async {
_key = key;
await closeDB();
}