android native C++编程实现数据库加密sqlcipher

sqlcipher是sqlite的加版本,分为免费版和收费版。

这里研究的是开源的免费版

https://github.com/sqlcipher/sqlcipher

Android码源默认提供了sqlite的native,jni和java版本,但没有提供sqlcipher,开发用到需要自己添加。

sqlcipher需要配置openssl,写一个android.bp

cpp 复制代码
android_sqlite_cflags = [
    "-DHAVE_USLEEP=1",
    "-DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576",
    "-DSQLITE_THREADSAFE=1",
    "-DNDEBUG=1",
    "-DSQLITE_ENABLE_MEMORY_MANAGEMENT=1",
    "-DSQLITE_TEMP_STORE=3",
    "-DSQLITE_ENABLE_FTS3_BACKWARDS",
    "-DSQLITE_ENABLE_LOAD_EXTENSION",
    "-DSQLITE_ENABLE_MEMORY_MANAGEMENT",
    "-DSQLITE_ENABLE_COLUMN_METADATA",
    "-DSQLITE_ENABLE_FTS4",
    "-DSQLITE_ENABLE_UNLOCK_NOTIFY",
    "-DSQLITE_ENABLE_RTREE",
    "-DSQLITE_SOUNDEX",
    "-DSQLITE_ENABLE_STAT3",
    "-DSQLITE_ENABLE_FTS4_UNICODE61",
    "-DSQLITE_THREADSAFE",
    "-Wno-unused-parameter",
    "-Wno-pointer-arith",
    "-Wno-unused-variable"
]

sqlcipher_cflags = [
    "-DSQLITE_HAS_CODEC",
    "-DHAVE_FDATASYNC=0",
    "-Dfdatasync=fsync",
]

sqlcipher_files = ["src/sqlite3.c"]

//APP_STL := c++_shared
//APP_ABI := armeabi-v7a arm64-v8a x86 x86_64
//APP_PLATFORM := android-26

// ANDROIDMK TRANSLATION ERROR: unsupported assignment to LOCAL_EXPORT_C_INCLUDES
// LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include/

//LOCAL_SRC_FILES := $(LOCAL_PATH)/lib/arm64-v8a/libcrypto.so
// ANDROIDMK TRANSLATION ERROR: unsupported include
// include $(PREBUILT_SHARED_LIBRARY)
cc_prebuilt_library_shared {
        name: "libcrypto2",
        target: {
            android_arm: {
                srcs: ["lib/armeabi-v7a/libcrypto.so"],
            },
            android_arm64: {
                srcs: ["lib/arm64-v8a/libcrypto.so"],
            },
        },
        strip: {
            none:true,
        },
        //shared_libs: ["libx", "libxx", "libxxx", "libxxxx"],
        check_elf_files: false,
        compile_multilib: "both"//32位和64位都预编译
}

cc_library_shared {
    name: "sqlite3_ext2",
    host_ldlibs: ["-llog"],
    srcs: sqlcipher_files,
    local_include_dirs: [
        "src",
        "include",
    ],
    cflags: android_sqlite_cflags + sqlcipher_cflags,
    //LOCAL_STATIC_LIBRARIES 	:= static-libcrypto
    shared_libs: ["libcrypto2",  "liblog",],

}

详细使用看:

GitHub - blogercn/android_sqlciphe: android natvity C/C++使用的加密数据库sqlciphe

可以用于ndk,可以复制到android源码供C++层开发使用

相关推荐
丘狸尾9 分钟前
[cisco 模拟器] ftp服务器配置
android·运维·服务器
微服务 spring cloud10 分钟前
配置PostgreSQL用于集成测试的步骤
数据库·postgresql·集成测试
先睡13 分钟前
MySQL的架构设计和设计模式
数据库·mysql·设计模式
弗罗里达老大爷14 分钟前
Redis
数据库·redis·缓存
仰望大佬0071 小时前
Avalonia实例实战五:Carousel自动轮播图
数据库·microsoft·c#
学不透java不改名1 小时前
sqlalchemy连接dm8 get_columns BIGINT VARCHAR字段不显示
数据库
只做开心事1 小时前
C++之红黑树模拟实现
开发语言·c++
一只路过的猫咪1 小时前
thinkphp6使用MongoDB多个数据,聚合查询的坑
数据库·mongodb
程序员老冯头2 小时前
第十五章 C++ 数组
开发语言·c++·算法