如何开始使用SQLCipher for android? [英] How to get started with SQLCipher for android?

查看:342
本文介绍了如何开始使用SQLCipher for android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用SQLCipher for android ...我已经使我们的应用程序使用SQLite,只想将其转换为SQLCipher。

I need to use SQLCipher for android...i've already made my app using SQLite and want to just convert it to SQLCipher.

问题是,我不知道SQLCipher。

The problem is, I know nothing about SQLCipher.

我已经阅读了这个链接: http://sqlcipher.net/sqlcipher-for-android/

I have read about it in this link: http://sqlcipher.net/sqlcipher-for-android/

但我不太清楚,还是。
我想知道你是否可以为安卓教程提供一些基本的sqlcipher,其中一切都是从绝对基础的一个简单的方法教。

But i'm not too clear, still. I was wondering if you could provide some basic sqlcipher for android tutorials, where everything is taught in an easy way from the absolute basics.

谢谢! p>

Thanks!

推荐答案

要正确使用SQL Cipher for Android,您必须使用外部库,并更改一些与您的数据库交互的代码。

To properly use SQL Cipher for Android you must use external libraries and change some of the code which interacts with your DB.


  1. 这些必须首先添加到您的项目中(在libs文件夹中。)请参阅这里获取这些: http://sqlcipher.net/sqlcipher-for-android/

其次,您需要将icudt4dl.zip文件添加到assets文件夹,此Zip随SQL Cipher库一起提供。

Secondly you need to add the icudt4dl.zip file to your assets folder, this Zip comes with the SQL Cipher libraries.

右键单击您的项目,转到属性然后Java构建路径,然后包括库,如commons-codec.jar,guava-r09.jar,sqlcipher.jar。一旦这样做,做一个清洁。

Right click your project, go to properties then Java build path then include libraries such as commons-codec.jar, guava-r09.jar, sqlcipher.jar. Once this is done, do a build clean.

然后在你的应用程序,而不是导入android.database.sqlite,你将导入import net.sqlcipher。数据库

Then within your App, instead of importing android.database.sqlite, you will import import net.sqlcipher.database

更改与数据库交互的任何代码,例如:

Change any code which interacts with the DB, example:

SQLiteDatabase.loadLibs );

SQLiteDatabase.loadLibs(context);

字符串dbPath = this.getDatabasePath(dbname.db)。getPath();

String dbPath = this.getDatabasePath("dbname.db").getPath();

SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbPath,dbPassword,null);

SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbPath,"dbPassword", null);

验证数据库是否加密,在Eclipse中转到DDMS透视图,文件浏览器选项卡,导航到数据/数据/,单击.db文件并选择获取设备文件,将其保存到您的桌面,并使用文本编辑器打开它。查找您已插入到数据库中的纯文本值,如果您仍然可以阅读它们,则出现错误。

Verify that the database is encrypted, go to DDMS perspective in Eclipse, click the file explorer tab, navigate to data/data/, click on the .db file and select get device file, save it to your desktop and open it with a text editor. Look for the plain text values you have been inserting into your database, if you can still read them, something has gone wrong.

在实现SQL Cipher之前检查一些SQLite教程也是一个好主意。这里提到一个好的:

It might also be a good idea to check out some SQLite tutorials before implementing SQL Cipher. A good one is mentioned here: Android sqlite database - where do i start as the tutorial has gone for notepad?

更新

这个答案现在已经过时,Eclipse几乎已不适用于Android开发。我最近不得不在Android Studio + Android 5 + 6上使用SQLCipher构建一个应用程序,这些是我遵循的步骤。

This answer is outdated now and Eclipse is practically deprecated for Android Development. I recently had to build an app using SQLCipher on Android Studio for Android 5 + 6 and these are the steps I followed.

在Android Studio中,可以包括SQLCipher在你的构建文件中的依赖。在构建gradle中更新您的依赖关系,以包括以下行:

In Android Studio, you can include SQLCipher as a dependency in your build file. Update your dependencies in build gradle to include the following line:

dependencies{
    compile 'net.zetetic:android-database-sqlcipher:3.5.4@aar'
}

版本:
https://mvnrepository.com/artifact/ net.zetetic / android-database-sqlcipher

我的应用程序不会构建,除非我删除lib文件夹和资产文件夹中的SQLCipher文件,之后它按预期工作。一旦你做了这些更改,运行一个build / clean并检查它是否工作。

My App wouldn't build unless I removed the SQLCipher files in the lib folder and the asset folder, but after that it worked as expected. Once you made these changes, run a build/clean and check if it works.

上述与更改代码相同的步骤仍然有效。

这篇关于如何开始使用SQLCipher for android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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