How to open Kotlin encrypted database on Flutter side? #3777
|
I am trying to open an encrypted database created with Room and SQLCipher 4.14 on Flutter but so far have no success. For unencrypted database I got it to work, just not the encrypted one. I tried both the SQLite3MultipleCiphers approach and the encrypted_drift approach on https://drift.simonbinder.eu/platforms/encryption/. Both of them gives me code 26 exception. I tried the unecrypted version and it works, so it must be something able the encryption. I have checked the hexKey and the byteArray and ensured it was correctly converted. Can anyone tell me what am I missing here?
The Kotlin code: SQLite3MultipleCiphers approach encrypted_drift approach |
Replies: 2 comments 1 reply
|
I think the SQLite3MultipleCiphers example should work. I've tried to reproduce this by opening a database with the Then, I ran this Dart program: import 'package:sqlite3/sqlite3.dart';
void main() {
final db = sqlite3.open('test.db');
print(db.select('pragma cipher'));
db.execute("pragma cipher = 'sqlcipher';");
db.execute("pragma legacy = 4;");
db.execute(
"pragma key = \"x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'\"",
);
print(db.select('pragma user_version'));
}Which was able to read the user version and decrypt the database. However, I see you get the exception in Kotlin and not in Dart. What pragmas are you running on the Kotlin side? Can you obtain a copy from the on-device database created with Kotlin to inspect it and make sure it's encrypted? Finally, I'll note that linking and loading two copies of SQLite with your app is generally a bad idea. In your case, your Kotlin code is using the native Android SQLCipher library while the For this reason, I would recommend the |
|
I figured it out. Use |
I figured it out. Use
PRAGMA hexkeyinstead ofPRAGMA key