androidsqliteencryptionfilesizesqlcipher-android

Unable to Zip Android SQLite Database After Encrypting With SQLCipher


I ship a read only database with my app including it in Assets/Database directory. All data is pre-populated beforehand.

After integrating with SQLCipher and encrypting the database I noticed that the APK size ballooned from 25MB to 150MB. Reason being is that the SQLite db file no longer gets compressed.

Android Studio normally will compress resources but after DB file is encrypted it seems zipping the file has no effect. I tried testing this outside with regular Zip & 7Zip and it makes no difference, zipped file is the same size as the original.

Un-encrypted database is around 130MB and when zipped takes only 18MB as most of it is text and strings zip very well. Zipping encrypted db file makes no difference in size.

Populating via server isn't a viable option as it would take forever due to amount of records. Downloading a full encrypted DB file from the server is the next option but it would still take too slow with a 140MB file.

Need to find an approach to ship encrypted DB with the app while still keeping the app size to a reasonable 20-30MB.

Any ideas?

Thanks.


Solution

  • Compression requires finding patterns in the data. Encryption removes all such patterns.

    You need to do the compression before the encryption. This is not possible with SQLCipher; you'd have to ship a compressed and encrypted .sql file, and then execute it on a new, encrypted database.