changeEncryptionKey method

Future<void> changeEncryptionKey(
  1. String newKey
)

Changes the key of the encrypted application database. Files keep their own key, stored inside the encrypted database, so they need no rewriting.

Implementation

Future<void> changeEncryptionKey(String newKey) async {
  if (_key == null) {
    throw StateError(
      'No encryption key in use: call useEncryptionKey first.',
    );
  }
  if (_scope != null) {
    throw StateError('The key cannot change inside a transaction.');
  }
  await (await _open()).executor.execute(
    'PRAGMA rekey = ${sqlLiteral(newKey)}',
  );
  _key = newKey;
}