Unable to Zip Android SQLite Database After Encrypting With SQLCipher

淺唱寂寞╮ 提交于 2019-12-07 16:34:38

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/34757644/unable-to-zip-android-sqlite-database-after-encrypting-with-sqlcipher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!