Introduction to SQLite encryption module for Android JNI environment

Source: Internet
Author: User

The free SQLite Open source code only provides two functions, only the implementation of these two functions to achieve the overall database encryption.

And then he took a little effort to find a well-realized open Source Library from the Internet http://sourceforge.net/projects/wxcode/files/Components/wxSQLite3/
Then write about how to integrate it into your so library.

First download the source code, locate Sqlite3/secure/src, and then copy all of the files (except Sqlite3.def) to the Jni folder under Androidproject and open the sqlite3.c file. Add one line of code to the front:

#define SQLITE_HAS_CODEC

Create a new Android.mk file under the Jni folder, and enter for example the following:

Local_path: =$(Call My-dir) include$(Clear_vars) local_module:= libsqlite3 local_src_files:= sqlite3secure.c #这里写的是相对路径include$(Build_static_library) # Starting here is the declaration of so library, where I use a self-loading script. Only need to specify # My_files_path to be able to load all CPP and C file include in their own initiative$(Clear_vars) Local_module: = Nativemy_files_path: =$(Local_path)/classesmy_files_suffix: =%.Cpp%.C # recursively traverse all the files under the folder rwildcard=$(Wildcard $ $)$(foreach D,$(Wildcard $*),$(Call Rwildcard,$d/, $) # gets the corresponding source file my_all_files: =$(foreach Src_path,$(My_files_path),$(Call Rwildcard,$(Src_path),*.*)) My_all_files: =$(My_all_files:$(My_cpp_path)/./%=$(My_cpp_path)%)My_src_list: =$(Filter $(My_files_suffix),$(my_all_files)) My_src_list: =$(My_src_list:$(Local_path)/%=%)# Remove the repeated words of the string define UNIQ =$(EvalSeen: =)$(foreach _, $,$(if $(Filter $_,${seen}),,$(EvalSeen + =$_)))${seen}endef# recursive traversal get all folders my_all_dirs: =$(Dir$(foreach Src_path,$(My_files_path),$(Call Rwildcard,$(Src_path),*/)) My_all_dirs: =$(Call Uniq,$(My_all_dirs)) #MY_ALL_DIRS: = # assigned to the NDK compiler system Local_src_files: =$(my_src_list) Local_c_includes: =$(My_all_dirs) Local_ldlibs: =-llog-ldllocal_static_libraries: = libsqlite3 # Add a static library include here$(Build_shared_library)

When used, only the need to

#include "sqlite3.h"

Then after the open database, call for example the following two functions:

Sqlite_apiintSqlite3_key (Sqlite3 *db,/ * Database to be rekeyed * /  Const void*pkey,/ * The key * /  intNkey/ * The key length * /); Sqlite_apiintSQLITE3_KEY_V2 (Sqlite3 *db,/ * Database to be rekeyed * /  Const Char*zdbname,/ * Name of the database * /  Const void*pkey,/ * The key * /  intNkey/ * The key length * /);

You can encrypt the database.
It is important to note that. It is only possible to invoke the arbitrary ability of the above two functions to encrypt the database immediately after the database is created. When an encrypted database needs to be manipulated, it needs to be called only once after the Open function database, which can be the normal operation of the database.

Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

Introduction to SQLite encryption module for Android JNI environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.