Recently used Wxsqlite encryption Sqlite3 database, just toss for a few days, in Xcode has been compiled not through, and later found in SQLITE3.C configuration, compiled smoothly through, too excited, haha, nonsense less say! Summary has been Android and iOS platform.
Wxsqlite3
WxSqlite3, as an extension component of wxwidgets, encapsulates the Sqlite3 API with C + + syntax, providing convenience for the use of Sqlite3 and, incidentally, encryption. Wxwidgets is a well-known C + + cross-platform UI framework. Two encryption algorithms are supported, the 128-bit Rijndael algorithm (default) and the 256-bit AES algorithm. Download: http://sourceforge.net/projects/wxcode/files/Components/wxSQLite3/
Unzip the WxSqlite3 tarball, locate the Sqlite3/secure/src folder file, and simply compile the sqlite3secure.c file.
--"Enable macros
You need to add a macro on top of sqlite3secure.c to enable encryption
#define Sqlite_has_codec
Enable 256-bit encryption, if not enabled, without
#define Codec_type codec_type_aes256
Add on top of sqlite3.h and sqlite3.c
#define Sqlite_has_codec
Android Support
1. Write a android.mk file, and all the above files are placed in the External/wxsqlite3 directory
Local_path: = $ (call My-dir) include $ (clear_vars) Local_module: = wxsqlite3_static local_module_filename: = Libwxsqlite3 #LOCAL_CFLAGS: = #-dsqlite_has_codec #-dcodec_type=codec_type_aes128 local_src_files: = SQLITE3SECURE.C local_export_c_includes: = $ (local_path) Local_c_includes: = $ (Local_path) include $ (build_static_ LIBRARY)
Add support in the project's Android.mk file
Local_whole_static_libraries + = Wxsqlite3_static
$ (call Import-module,external/wxsqlite3)
iOS support
Add the code directory, find the folder we just added, and add all the files except Sqlite3.h and sqlite3secure.c to delete the reference
Related API function interface
After SQLite has added encryption and decryption, the following methods are used:
1. After calling the Sqlite3_open () function to open the database, call the Sqlite3_key () function to set the password for the database;
2, if the database has a password before, call the Sqlite3_key () function to set the correct password to work properly;
3, if a database has no password, and already have data, you can no longer set a password for it;
4, if you want to change the password, you need to call the Sqlite3_rekey () function after the first step to set a new password;
5, set the password of the SQLite database, can not be opened with third-party tools;
COCOS2DX using Wxsqlite Open source encryption SQLite3 database