`
gegaosong
  • 浏览: 37886 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

SQLCipher加解密Android sqlite

阅读更多
具体的操作:http://sqlcipher.net/sqlcipher-for-android/ 

如果sql语句执行过程中SQLException: SQL logic error or missing database ,那就是你的zip包的版本太低了,请升级到最新的版本(用我附件中的版本也就没问题)



SQLCipher for Android Application Integration
This tutorial will cover integrating the binaries of SQLCipher for Android into an Android application. This tutorial assumes the Android SDK is already installed on the local development machine.

Create sample Android application
To create a sample Android application, issue the following commands:

% mkdir demo-app
% cd demo-app
% android create project \
  --target android-10 \
  --name demoapp \
  --path . \
  --activity HelloSQLCipherActivity \
  --package com.demo.sqlcipher
Obtaining binaries
The source code for SQLCipher for Android is publicly maintained on Github.com, the current binary release can be found here. For information on building the source of SQLCipher for Android, please see the instructions below. We will manually download and extract the contents of the compressed tar file into your application root directory with the commands below:

% curl -L -o SQLCipherforAndroid2.0.5.zip https://github.com/downloads/sqlcipher/android-database-sqlcipher/SQLCipher%20for%20Android%202.0.5.zip
% unzip SQLCipherforAndroid2.0.5.zip
We need to copy the various library and asset files over into the root directory of our application. Execute the following commands:

% cp -R SQLCipher\ for\ Android\ 2.0.5/libs/* libs
% cp -R SQLCipher\ for\ Android\ 2.0.5/assets .
The files for your demo application should look similar to this structure:



Integration
Launch Eclipse and choose File -> New -> Android Project from the menu. Give the project a name and choose Create project from existing source pointing to your application root directory. It should look similar to this:



Next we need to reference the 3 jar files in our libs directory. Right click on the project node in the Package Explorer and select Build Path -> "Configure Build Path...". Select the Libraries tab and press the "Add JARs..." button. Select commons-codec.jar, guava-r09.jar and sqlcipher.jar. After selecting these three jars, the screen should appear like this:



Next we will modify the source of the default activity to properly initialize the native libraries for SQLCipher and then create our database file inserting a record. In particular, note the import of net.sqlcipher.database.SQLiteDatabase instead of android.database.sqlite.SQLiteDatabase as well as the call to SQLiteDatabase.loadLibs(this). The call to SQLiteDatabase.loadLibs(this) must occur before any other database operation.

package com.demo.sqlcipher;

import java.io.File;
import net.sqlcipher.database.SQLiteDatabase;
import android.app.Activity;
import android.os.Bundle;

public class HelloSQLCipherActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        InitializeSQLCipher();
    }

    private void InitializeSQLCipher() {
        SQLiteDatabase.loadLibs(this);
        File databaseFile = getDatabasePath("demo.db");
        databaseFile.mkdirs();
        databaseFile.delete();
        SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(databaseFile, "test123", null);
        database.execSQL("create table t1(a, b)");
        database.execSQL("insert into t1(a, b) values(?, ?)", new Object[]{"one for the money",
                                                                        "two for the show"});
    }
}
The sample application should now be able to run on either an emulator or device.


SQLCipher for Android Build Tutorial
This tutorial will cover building the source code for SQLCipher for Android from scratch. This tutorial targets revision 7 of the Android NDK and is intended for complication under Linux or OSX environments.

System environment requrements
In order to build the source of SQLCipher for Android several tools are required. Several development kits including the Android SDK, Android NDK and the JDK need to be present on the build machine. We will need the ANDROID_NDK_ROOT environment variable available on the PATH. You will also need Git to acquire the source tree. To verify your PATH is properly configured, execute the following command:

% which ndk-build
/Users/nparker/bin/android-ndk/ndk-build
If you receive ndk-build not found you will need to add the following to your .bashrc or corresponding shell configuration file. Note the ~/bin/android-ndk path below represents the location on my machine for the root directory of the Android NDK, adjust accordingly:

export ANDROID_NDK_ROOT=~/bin/android-ndk
export PATH=$ANDROID_NDK_ROOT:$PATH
We will use Make as our base build tool for interacting with the NDK toolchain.

Get the source
The source code for SQLCipher for Android is maintained publicly on Github.com. We will start by cloning the repository locally:

% cd ~/code
% git clone git://github.com/sqlcipher/android-database-sqlcipher.git
Building
The process of building the code is split into two different phases. The first time this is performed we need to initialize various git submodules that SQLCipher for Android depends on. This is all automated through Make.

% cd android-database-sqlcipher
% make init
Once git has finished pulling down the various submodules required for compilation, we can begin the build process:

% make
This process will take some time to complete. Once it has completed, you should have the following files available for integration into your application's libs directory:

% tree libs
libs
├── armeabi
│   ├── libdatabase_sqlcipher.so
│   ├── libsqlcipher_android.so
│   └── libstlport_shared.so
├── commons-codec.jar
├── guava-r09.jar
└── sqlcipher.jar
Localization dependencies
SQLCipher for Android depends on localization data from the ICU project. SQLCipher for Android will attempt to use a system provided ICU localization data file called icudt46l.dat located in the /system/usr/icu directory if available. If that is not found, SQLCipher for Android will attempt to unzip the icudt46l.zip file located within the applications asset directory. It is recommended that the icudt46.zip file be included with your application for best platform compatibility. If you need to adjust the size of the localization data for your application, a ICU data library customizer is available here.
分享到:
评论
1 楼 RobustTm 2013-07-07  
想问ls成功了么
我git下载代码后make init后 make不成功

相关推荐

    使用Sqlcipher对sqlite数据库进行加解密

    本文将详细介绍如何在Android应用中使用Sqlcipher对sqlite数据库进行加解密。 首先,你需要在你的项目中集成Sqlcipher库。通常,可以通过Gradle依赖管理来添加Sqlcipher的依赖。在你的app级别的build.gradle文件中...

    Sqlcipher 加密sqlite androidstudio as

    Sqlcipher是一种开源的数据库加密解决方案,它为SQLite数据库提供了强大的加密功能,确保在Android Studio (AS) 开发环境中存储的数据安全。在Android应用开发中,SQLite通常被用来管理应用程序的本地数据,但如果不...

    SqlCipher.exe Sqlite加密查看工具

    这不仅可以应用于桌面应用,还可以用于移动平台,如Android和iOS,因为Sqlite是跨平台的数据库解决方案。 SqlCipher.exe作为一个便捷的工具,有助于数据库管理员和开发者测试、调试和管理加密的Sqlite数据库。它...

    加解密android数据库sqlite

    本文将围绕"加解密Android数据库SQLite"这一主题,详细介绍如何实现这一功能。 首先,理解SQLite数据库的基本原理。SQLite是一个轻量级的、自包含的、关系型数据库引擎,它允许开发者在Android应用中存储和管理结构...

    SQLCipher为sqlite数据库设置密码

    SQLCipher的工作原理是通过使用AES(Advanced Encryption Standard)加密算法对SQLite数据库进行加解密。在应用层,用户可以设置一个密码,这个密码会被用来生成一个加密密钥。当数据库被打开时,必须提供正确的密码...

    cpp-SQLCipher是一个SQLite扩展为数据库文件提供256位AES加密

    5. **跨平台支持**:SQLCipher 兼容多种操作系统,包括Windows、macOS、Linux、iOS 和 Android,为开发者提供了广泛的开发环境选择。 ### 使用SQLCipher的步骤 1. **安装SQLCipher**:首先,你需要下载并安装...

    解密SQLCipher数据库Activity.java

    解密 android-database-sqlcipher:3.5.7生成的加密数据库文件,可拿来直接用,方法简单有效

    android 的sqlite数据库加密实现

    在Android应用开发中,SQLite是一个...通过以上介绍,我们了解了在Android中使用SQLCipher实现SQLite数据库加密的重要性、方法以及注意事项。在实际项目中,可以根据需求选择适合的加密策略,确保应用的数据安全性。

    SQLcipher2.1,SQLite数据库管理工具

    6. **兼容性**:SQLcipher通常与SQLite的主要版本保持兼容,这意味着你可以用它来加密和解密不同版本的SQLite数据库。 7. **备份与迁移**:加密的数据库备份同样需要密钥才能恢复,因此备份过程中需要同时保存密钥...

    sqlcipher-for-android-v3.5.6.zip

    SQLCipher for Android是一款针对Android平台的开源加密数据库解决方案,它基于SQLite并提供了强大的加密功能,保护应用程序中的数据安全。在v3.5.6版本中,这个库包含了多个架构的本地库(.so文件)以及Java接口...

    sqlcipher3.0.1 Android数据库解密工具 for Win

    SqlCipher 在SQLite数据库的基础上添加了一层加密,通过使用AES(高级加密标准)算法来对数据进行加解密。当应用程序打开数据库时,SqlCipher会要求提供一个密钥,只有提供正确的密钥才能访问数据,从而防止未经...

    Android数据库安全解决方案,使用SQLCipher进行加解密.docx

    # Android数据库安全解决方案:使用SQLCipher进行加解密 ## 一、背景介绍与问题提出 随着移动互联网的发展,智能手机已成为人们日常生活中不可或缺的一部分。在众多的移动操作系统中,Android以其开放性和灵活性受...

    Android-SQLite和SQLCipher性能测试

    本文将深入探讨Android环境下SQLite与SQLCipher的性能测试,以及它们在实际应用中的优缺点。 首先,SQLite作为Android默认的数据库,其性能主要体现在快速的本地数据存取、简单的API接口和良好的兼容性。它的优势...

    SQLCipher加密

    其核心原理是通过对SQLite数据库的页级加密来保护数据,使用AES(Advanced Encryption Standard)算法进行加解密,保证了数据在存储和传输过程中的隐私性。 在标题中提到的"SQLCipher加密",是指使用SQLCipher对...

    android-database-sqlcipher-v3.5.7 Android安卓数据库加密开源项目

    本文将深入探讨一个流行的开源项目——"android-database-sqlcipher-v3.5.7",它是专门为Android平台设计的SQLite数据库加密解决方案。 SqlCipher是一款基于SQLite的开源加密库,它提供了透明的数据加密功能,允许...

    sqlcipher-for-android-v3.5.4

    《SQLCipher for Android v3.5.4:安全的SQLite数据库解决方案》 在移动设备上,数据安全性至关重要,尤其是在处理用户敏感信息时。SQLCipher for Android是针对Android平台的一个强大的数据库加密解决方案,它将...

    sqlcipher-android.zip

    总的来说,`sqlcipher-android.zip`提供的这两个库为Android开发者提供了一套完整的解决方案,可以在保持高效数据库操作的同时,确保存储在SQLite数据库中的用户数据得到保护。这在处理个人数据、金融信息或其他敏感...

    sqlcipher for android

    1. **透明加密**:SQLCipher对SQLite的查询语句和结果集进行加解密,无需修改应用代码,即可实现数据库的加密和解密。 2. **密钥管理**:开发者可以设置自定义的密钥来加密数据库,密钥的变化会直接影响数据库的访问...

Global site tag (gtag.js) - Google Analytics