加密SQLite数据库而不增加应用程序大小?

时间:2014-07-11 06:51:55

标签: android database encryption sqlcipher

有没有办法加密我的Android应用程序的数据库,减少应用程序的大小? 我已经尝试了SQLcipher,但它增加了我的应用程序的大小10MB,这是巨大的。

4 个答案:

答案 0 :(得分:2)

The increase of 10MB in your APK when using SqlCipher can be avoided by shipping a separate APK for each Android architecture you want to target.

For performance and cross platform support reasons SqlCipher is implemented in C code and built as a native Android .so library using the Android NDK. A different library is built for each Android architecture it supports, which in the case of SqlCipher are:

  • armeabi
  • armeabi-v7a
  • x86

To minimize the file size increase caused by SqlCipher you can build a seperate APK that only includes the architecture that matches your users device. Take a look at the Android developers site on how to publish multiple APK's targeting different device configurations.

During my testing following this technique reduced my APK from 10MB to 4MB.

For further information this article details how to implement SqlCipher on Android and explains the file size increase.

答案 1 :(得分:0)

目前有两种主要的数据库被广泛用于Java / Android应用程序。在这种情况下, SqlLite H2数据库。根据{{​​3}},我们可以看到两个数据库之间的一组差异特征。例如,两个数据库都具有 ACID功能交易参照完整性 Unicode表示。但是,只有 H2数据库具有加密数据强力保护原生网络加密

此加密机制使用AES算法,可以对数据库文件进行加密。由于H2数据库使用AES来控制数据文件,一般来说,我们可以推断它可能非常慢而不是SqlLite,因为en [de]解密由AES使用。因此,当使用H2数据库时,en [de] crypt会在效率方面增加开销成本。

总之,当加密数据很重要时,H2数据库可以作为小项目的有用替代方案。此外,重要的是要注意更多的实验(经验基准)对于涉及展位数据库的性能问题的结论非常重要。请注意, small 轻微缓慢是主观的,因为我们需要进行实验评估以更精确地比较两个(或其他)数据库。

使用了一些有用的参考资料:

答案 2 :(得分:0)

这取决于您的实际需求,但在您写入/读取数据库之前,一种简单的方法是加密/解密数据本身。这对apk大小的影响微乎其微,但您需要付出更多努力。

如果需要高安全性,只需接受10MB并继续生活: - )

答案 3 :(得分:0)

如果您使用的是Gradel,请在gradle配置中添加一个abiFilter,例如

ndk {
    abiFilters "armeabi", "armeabi-v7a"
}

如果这样做不能减小大小,则需要重新考虑使用SQLCipher为您的应用程序提供本地数据加密。