-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to use isolates with EncryptedMoor #451
Comments
The Just to be sure, the database you tried to connect to via a |
Yes, the errors in both cases were created using I'm working on medical-based applications so I do need encryption. If you're able to point me in the right direction I'm happy to help contribue. |
@cadaniel I am using SQLCipher in my app also, and to use moor_ffi this is what I have done. Some things to note: This has been tested on Flutter desktop, haven't tried on Android/iOS. It should work, but you need to provide the SQLCipher libraries yourself. In your import 'package:moor_ffi/open_helper.dart';
void main(){
open.overrideForAll(sqlcipherOpen);
}
DynamicLibrary sqlcipherOpen() {
if (Platform.isLinux || Platform.isAndroid) {
return DynamicLibrary.open('libsqlcipher.so');
}
if (Platform.isMacOS || Platform.isIOS) {
return DynamicLibrary.open('/usr/lib/libsqlcipher.dylib');
}
if (Platform.isWindows) {
DynamicLibrary.open('libsqlcipher.dll');
}
throw UnsupportedError(
'moor_ffi does not support ${Platform.operatingSystem} yet');
} class MyDatabase extends _$MyDatabase {
MyDatabase(Directory directory)
: super(
VmDatabaseEncrypted(
File(dbPath),
password: "password",
logStatements: true,
),
);
} // sqlcipher_moor_ffi.dart
import 'dart:async';
import 'dart:io';
import 'package:moor/backends.dart';
import 'package:moor/moor.dart';
import 'package:moor_ffi/moor_ffi.dart';
class VmDatabaseEncrypted extends DelegatedDatabase {
/// Creates a database that will store its result in the [file], creating it
/// if it doesn't exist.
factory VmDatabaseEncrypted(
File file, {
String password = '',
bool logStatements = false,
}) {
final vmDatabase = VmDatabase(file, logStatements: logStatements);
return VmDatabaseEncrypted._(vmDatabase, password);
}
factory VmDatabaseEncrypted.memory({
String password = '',
bool logStatements = false,
}) {
final vmDatabase = VmDatabase.memory(logStatements: logStatements);
return VmDatabaseEncrypted._(vmDatabase, password);
}
VmDatabaseEncrypted._(
VmDatabase vmDatabase,
this.password,
) : super(
_VmEncryptedDelegate(vmDatabase.delegate, password),
logStatements: vmDatabase.logStatements,
isSequential: vmDatabase.isSequential,
);
final String password;
}
class _VmEncryptedDelegate extends DatabaseDelegate {
final String password;
final DatabaseDelegate delegate;
_VmEncryptedDelegate(
this.delegate,
this.password,
);
@override
Future<void> open([GeneratedDatabase db]) async {
await delegate.open(db);
await delegate.runCustom('PRAGMA KEY = "$password"', <dynamic>[]);
return Future.value();
}
@override
FutureOr<bool> get isOpen => delegate.isOpen;
@override
Future<void> runBatched(List<BatchedStatement> statements) {
return delegate.runBatched(statements);
}
@override
Future<void> runCustom(String statement, List args) {
return delegate.runCustom(statement, args);
}
@override
Future<int> runInsert(String statement, List args) {
return delegate.runInsert(statement, args);
}
@override
Future<QueryResult> runSelect(String statement, List args) {
return delegate.runSelect(statement, args);
}
@override
Future<int> runUpdate(String statement, List args) {
return delegate.runUpdate(statement, args);
}
@override
TransactionDelegate get transactionDelegate => delegate.transactionDelegate;
@override
DbVersionDelegate get versionDelegate => delegate.versionDelegate;
}
|
Thanks @davidmartos96 I have a fork at https://github.com/cadaniel/moor that I'm starting to take a look at this. I took your solution however I'm getting "/usr/lib/libsqlcipher.dylib" doesn't exist. Running on both iOS simulator and on a physical device. Seems to work perfectly on Android though. |
@cadaniel As I said, you would need to bundle the SQLCipher libraries in each platform yourself. I don't have much experience on how to do that on iOS. |
How did you fix the iOS implementation? Can't figure out how to encrypt my iOS database |
@vanlooverenkoen How did you fix iOS issue, in my emulator and physical device the libsqlcipher also not exists |
@iampopal we did this: And fully read this: #1810 We only had the issue in release mode |
So I've tried two attempts
With what's given on the example docs
gives me the error
When I use the other executor
final executor = EncryptedExecutor(path: request.targetPath, password: request.password, logStatements: true);
gives me the error
If I use an unencrypted database the first executor works just fine.
The text was updated successfully, but these errors were encountered: