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

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

问题描述

你好我运行的应用程序我已经有一个现有的源码数据库。而现在的问题是,任何人都可以从设备拉 SQLite数据库并且可以使用它。现在我需要 sqlite的文件加密。我发现, SQLCipher 使用的SQLite数据库进行加密。但真正的问题是我没有用 SQLCipher 任何想法,也不知道它是如何工作。尝试使用不同的项目。没有什么帮助。请谁能告诉我如何加密我的SQLite数据库。

在此先感谢。

解决方案

步骤#0:添加code到你的UI提示用户输入密码

步骤#1:下载 SQLCipher为Android ZIP文件

第2步:解压缩ZIP文件,然后导航到具有资产/ 库/ 文件夹。

第三步:在资产/ 目录的内容复制到项目的资产/ 目录

第四步:复制库/ 目录中的内容到项目的库/ 目录。摇篮/ Android的Studio用户还需要添加一行到顶层依赖关闭装载了库/ ,如果你没有一个了。

步骤#5:更换所有相关的 android.database * android.database.sqlite * 进口。他们SQLCipher为Android当量。如果您使用的是IDE,可以帮助您解决缺少进口(例如,<大骨节病>控制 - <大骨节病>移 - <大骨节病> 0 在Eclipse),最简单的事情做的是摆脱所有现有的 android.database。* android.database.sqlite。* 的进口,让IDE的帮助下解决这些问题。当有选择选择 net.sqlcipher 进口。

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

这将适用于新的应用程序启动新的数据库。有涉及与现有的用户升级现有的应用程序,如果你想允许这些用户切换到加密数据库的额外工作。

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.

Thanks in advance.

解决方案

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

Step #1: Download the SQLCipher for Android ZIP file.

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

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

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.

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.

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天全站免登陆