davidmartos96 / sqflite_sqlcipher

SQLite flutter plugin
BSD 2-Clause "Simplified" License
99 stars 44 forks source link

Database generated is not encrypted #54

Closed DineshKachhot closed 2 years ago

DineshKachhot commented 2 years ago

I am using sqflite_sqlcipher: ^2.1.0 to encrypt database. But I am getting following two errors.

1) While creating new database database generated is not encrypted. While open it in DB Browser for sqlite it is not encrypted by any password, while generate database password is passed.

await openDatabase(path, version: _databaseVersion, onCreate: _onCreate, onUpgrade: _onMigrate, password: _encryptionKey, );

2) While open encrypted database using the same code above, it give me error like 'file is not a database'.

davidmartos96 commented 2 years ago

Which device are you using?

DineshKachhot commented 2 years ago

I am testing on iOS Simulator, because it's easy for me to go to database path to check database encryption.

davidmartos96 commented 2 years ago

If you are on iOS it's possible that you skipped the extra configuration steps in the Readme. What you are experiencing can happen if some other dependency you have uses normal SQLite under the hood. It is not guaranteed that SQL cipher will get loaded. Also make sure you try to reinstall at least once. Otherwise you may be opening a database that has already been created without encryption.

DineshKachhot commented 2 years ago

I guess there is not extra configurations for iOS, except we just have to import sqflite_sqlcipher replacing normal sqflite dependancy.

I agree with you, I suspect it is using sqflite somewhere, I have no dependancy for sqflite in pubspec file, even I cleared pub cache to be sure, even I tried breakpoint in sqflite_sqlcipher library, it's coming there as well.

Yes I am reinstalling app every time I make changes related to database.

davidmartos96 commented 2 years ago

To be sure this if that is what's happening, try running the following select inside the app and see what you get.

db.rawQuery("PRAGMA cipher_version")

If you get something like SQLCipher community then it's a different issue.

davidmartos96 commented 2 years ago

The extra steps I refer to are at the bottom of the Readme. It's possible that you don't use sqlite directly, but some other dependency in your project does.

DineshKachhot commented 2 years ago

result of db.rawQuery("PRAGMA cipher_version") is [].

davidmartos96 commented 2 years ago

Then normal SQLite is getting loaded instead by the OS. Can you share the pubspec here?

DineshKachhot commented 2 years ago

Here is my pubspec.yaml code

`dependencies: flutter: sdk: flutter flutter_localizations: sdk: flutter

cupertino_icons: ^1.0.3 hexcolor: ^2.0.4 http: ^0.13.3 flutter_secure_storage: ^4.2.0 intl: ^0.17.0 geolocator: ^7.3.1 geocoding: ^2.0.0

sqflite: ^2.0.0+3

path_provider: ^2.0.2 battery: ^2.0.3 app_settings: ^4.1.1 connectivity: ^3.0.6 permission_handler: ^8.1.4+2 background_fetch: ^1.0.1 flutter_local_notifications: ^6.1.0 flutter_platform_widgets: ^1.9.5 dotted_border: ^2.0.0 image_picker: ^0.8.2 signature: ^4.1.1 url_launcher: ^6.0.9 fluttertoast: ^8.0.7 cached_video_player: ^1.0.3 # not null safe signature_pad_widget: dashed_container: ^1.0.1 device_info: ^2.0.2 transparent_image: ^2.0.0 flutter_staggered_grid_view: ^0.4.0 firebase_core: ^1.7.0 firebase_crashlytics: ^2.2.3 cached_network_image: ^3.1.0 mime: ^1.0.0 retry: ^3.1.0 sentry_flutter: ^5.1.0 pull_to_refresh: ^2.0.0 shared_preferences: ^2.0.6 grouped_list: ^4.1.0 adaptive_action_sheet: ^2.0.0 flutter_apns: ^1.5.1 firebase_messaging: ^10.0.8 flutter_spinkit: ^5.0.0 firebase_auth: ^3.1.3 cloud_firestore: ^2.4.0 flutter_keyboard_visibility: ^5.0.3 timeago: ^3.1.0 firebase_storage: ^10.0.5 flutter_slidable: ^0.6.0 share: ^2.0.4 photo_view: ^0.12.0 google_maps_flutter: screenshot: local_auth: safe_device: ^1.0.9 sqflite_sqlcipher: ^2.1.0`

davidmartos96 commented 2 years ago

There you have it: cached_network_image: ^3.1.0

That package uses SQLite under the hood for caching. If you include the dependency_override from the Readme it should work

DineshKachhot commented 2 years ago

You where right @davidmartos96, dependency_override was missing, it's working now, thanks for the quick help.

davidmartos96 commented 2 years ago

Glad it worked!