加密sqlite数据库Android: [英] encrypt sqlite database Android:

查看:30
本文介绍了加密sqlite数据库Android:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在运行的应用程序中,我已经有一个现有的 sqlite 数据库.现在的问题是任何人都可以从设备中提取 sqlite 数据库 并可以使用它.现在我需要加密sqlite文件.我发现SQLCipher 是用来加密sqlite 数据库的.但真正的问题是我对 SQLCipher 一无所知,也不知道它是如何工作的.尝试使用不同的项目.没什么帮助.请任何人告诉我如何加密我的sqlite数据库.

Hi in my running app i already have an existing sqlite database. And now the problem is anybody can pull the sqlite database from device and can be use it. Now i need to encrypt the sqlite file. I found that SQLCipher is used to encrypt the sqlite database. But the real problem is i don't have any idea with SQLCipher and don't know how it works. Try to use different projects. Nothing help. Please anyone tell me how to encrypt my sqlite database.

提前致谢.

推荐答案

第 0 步:将代码添加到您的 UI 以提示用户输入密码.

Step #0: Add the code to your UI to prompt the user to enter a passphrase.

第 1 步:下载 SQLCipher for Android ZIP 文件.

第 2 步:解压缩 ZIP 文件并导航到包含 assets/libs/ 文件夹的目录.

Step #2: UnZIP the ZIP file and navigate to the directory that has an assets/ and a libs/ folder.

第 3 步:将 assets/ 目录的内容复制到项目的 assets/ 目录中.

Step #3: Copy the contents of the assets/ directory into your project's assets/ directory.

第 4 步:将 libs/ 目录的内容复制到项目的 libs/ 目录中.如果您还没有加载 libs/ 的内容,Gradle/Android Studio 用户还需要在顶级 dependencies 闭包中添加一行.

Step #4: Copy the contents of the libs/ directory into your project's libs/ directory. Gradle/Android Studio users will also need to add a line to the top-level dependencies closure loading up the contents of libs/, if you do not have one already.

第 5 步:将所有相关的 android.database.*android.database.sqlite.* 导入替换为它们的 SQLCipher for Android 等效项.如果您使用的 IDE 可以帮助您解决丢失的导入(例如,Eclipse 中的 Ctrl-Shift-O),最简单的方法是做的是摆脱所有现有的 android.database.*android.database.sqlite.* 导入,让 IDE 帮助解决它们.选择时选择 net.sqlcipher 导入.

Step #5: Replace all relevant android.database.* and android.database.sqlite.* imports with their SQLCipher for Android equivalents. If you are using an IDE that can help you resolve missing imports (e.g., Ctrl-Shift-O in Eclipse), the easiest thing to do is to get rid of all existing android.database.* and android.database.sqlite.* imports and let the IDE help resolve them. Choose the net.sqlcipher imports when given the choice.

第 6 步:您现在将在打开数据库的一些方法上遇到编译器错误(例如,SQLiteOpenHelper 上的 getReadableDatabase()),您现在需要传递您在步骤 #0 中从用户那里收集的密码.

Step #6: You will now have compiler errors on a few methods where you open a database (e.g., getReadableDatabase() on SQLiteOpenHelper), where you now need to pass in the passphrase you collected from the user in Step #0.

这适用于使用新数据库启动的新应用.如果您希望允许这些用户切换到加密数据库,则还需要使用现有用户升级现有应用程序.

This will work for new apps starting up with new databases. There is additional work involved to upgrade an existing app with existing users, if you want to allow those users to switch to an encrypted database.

这篇关于加密sqlite数据库Android:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆