mac

安装 brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安装 sqlcipher

brew options sqlcipher
brew install sqlcipher

这部分不知道有没有起作用

export LDFLAGS="-L/usr/local/lib"
export CPPFLAGS="-I/usr/local/include -I/usr/local/include/sqlcipher"
export CXXFLAGS="$CPPFLAGS"

克隆 sqlcipher 源码,并链接

git clone https://github.com/sqlcipher/sqlcipher.git
pushd sqlcipher make clean ./configure --enable-tempstore=yes --enable-load-extension --disable-tcl --with-crypto-lib=commoncrypto CFLAGS="-DSQLITE_HAS_CODEC -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS5" LDFLAGS="-framework Security -framework Foundation"
make

成功后该文件夹下出现 .libs 隐藏文件夹

创建 custom-binding.gyp 文件

{
"includes": [ "deps/common-sqlite.gypi" ],
"variables": {
},
"targets": [
{
"target_name": "<(module_name)",
"include_dirs": [
"<!(node -e \"require('nan')\")",
"/Users/jinghongqiu/Desktop/sqlcipher/"
],
"libraries": [
"/Users/jinghongqiu/Desktop/sqlcipher/.libs/libsqlcipher.a"
],
"sources": [
"src/database.cc",
"src/node_sqlite3.cc",
"src/statement.cc"
]
},
{
"target_name": "action_after_build",
"type": "none",
"dependencies": [ "<(module_name)" ],
"copies": [
{
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
"destination": "<(module_path)"
}
]
}
]
}

/Users/jinghongqiu/Desktop/sqlcipher 需要替换成 sqlcipher 克隆下来的路径

在 electron 项目中执行命令

echo "Copying custom binding.gyp (node-sqlite3)"
cp custom-binding.gyp node_modules/sqlite3/binding.gyp echo "Rebuilding node-sqlite3 bindings with statically linked SQLCipher (libsqlcipher.a)"
npm rebuild sqlite3 --build-from-source --static_linking_path=/Users/jinghongqiu/Desktop/sqlcipher/.libs/libsqlcipher.a --runtime=electron --target=4.0.8 --dist-url=https://atom.io/download/electron

/Users/jinghongqiu/Desktop/sqlcipher 需要替换成 sqlcipher 克隆下来的路径

--target=4.0.8 中的数字为 electron 的版本

使用

// 在 electron 里才能使用
var sqlite3 = require('sqlite3')
var db = new sqlite3.Database('./test.sqlcipher') db.serialize(() => {
db.run("PRAGMA KEY = 'secret'")
db.run("CREATE TABLE messages(id INTEGER, user VARCHAR, msg TEXT)") db.run("INSERT INTO messages(id, user, msg) VALUES (1, 'coolaj86', 'this is test message number one')") db.get("SELECT * FROM messages", (err, data) => {
if (err) {
console.error(err)
return
}
console.log(data)
})
})

用可视化工具打开 test.sqlcipher ,如果需要输入密码则集成成功。输入密码 secret,如果无法打开,则有可能是可视化工具问题(如 SQLiteManager 正确密码也无法打开)

参考

Building SQLCipher for node.js on Raspberry Pi 2

Setting up SQLCipher with node-sqlite3 and Electron

在 Node.js 中使用 SQLCipher

electron 集成 SQLCipher的更多相关文章

  1. electron 集成 nedb / sqlite3

    nedb nedb 无法创建文件 // webpack 构建的前提 externals: process.env.web ? {} : { "nedb": "requir ...

  2. nodejs集成sqlite

    正在物色node上面的轻量级嵌入式数据库,作为嵌入式数据库的代表,sqlite无疑是个理想的选择方案.npm上集成sqlite的库主要有两个——sqlite3和realm. realm是一个理想的选择 ...

  3. iOS SQLite解密之SQLCipher

    开门见山,本文主要讲在Mac下使用SQLCipher编译解密数据库文件方法,iOS项目集成SQLCipher自己可以百度,网上帖子很多. 官方集成文档:https://www.zetetic.net/ ...

  4. Sentry快速开始并集成钉钉群机器人

    Sentry(直译为:哨兵)是一个开源错误跟踪服务,帮助开发人员实时监控和修复崩溃 Sentry本质上是一种帮助您实时监控和修复崩溃的服务 1.  安装客户端SDK 这里我们安装Java平台的SDK, ...

  5. ORMLite整合SQLCipher

    Android数据库加密,目前就是SQLCipher对SQLite整体加密,微信也是使用这种方式.开源,且支持很多平台. SQLCipher虽说开源了,但是编译好的jar和so文件,还是要收费的. 但 ...

  6. Electron结合React开发环境遇到的问题

    链接 将create-react-app与electron集成在了一个项目中.但是在React中无法使用electron 当在React中使用require('electron')时就会报TypeEr ...

  7. 将现有vue项目基于electron打包成桌面应用程序

    一.前言 项目本来打算采用B/S架构去做的,浏览器网址方式打开还是让用户不方便: 二.使用electron集成桌面应用 本身项目是使用vue-cli开发的,在使用electron之前,需要将本身的项目 ...

  8. 什么是electron

    Electron 是什么 定义 Electron是一个能让你使用传统前端技术(Nodejs, Javascript, HTML, CSS)开发一个跨平台桌面应用的框架.这里所说的桌面应用指的是在Win ...

  9. Electron结合React,在渲染进程中使用 node 模块

    Electron结合React,在渲染进程中使用 node 模块 问题 将create-react-app与electron集成在了一个项目中.但是在React中无法使用electron.当在Reac ...

随机推荐

  1. assert.equal()

    assert.equal(actual, expected[, message]) 使用相等运算符(==)测试 actual 参数与 expected 参数是否相等(通俗解释equal方法接受三个参数 ...

  2. Blast 如何使用Blast+(Linux)转载

    下载数据 #此处下载对应物种的数据库ftp://ftp.ncbi.nih.gov/genomes/,下载fna格式的即可   wget ftp://ftp.ncbi.nih.gov/genomes/A ...

  3. 剑指offer(65):获取数据流中的中位数

    参考 https://blog.csdn.net/u011080472/article/details/51291089 题目描述 如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值,那么中位 ...

  4. 删除docker私有仓库中的镜像

    1.搭建私有仓库 (1)拉取私有仓库镜像 docker pull registry(2)启动私有仓库容器 docker run ‐di ‐‐name=registry ‐p 5000:5000 reg ...

  5. MCP|LQD|Data-independent acquisition improves quantitative cross-linking mass spectrometry (DIA方法可提升交联质谱定量分析)

    文献名:Data-independent acquisition improves quantitative cross-linking mass spectrometry (DIA方法可提升定量交联 ...

  6. centos 7 安装python3

    centos系统默认已安装python2.7,python3需要手动安装.以上是安装步骤 一.备份原来的2.7版本 首先看一下默认的python2.7在哪里 [root@apple ~]# cd / ...

  7. sys_guid()

    create extension "uuid-ossp"; create or replace function sys_guid() returns uuid as $$sele ...

  8. Ryzen 移动平台上安装 Gentoo Linux

    Linux 内核对于跟进支持 Ryzen 移动低压 CPU 的热情似乎和市面上寥寥无几的 Ryzen 笔记本热度十分吻合.虽然从 Linux 4.11 起就对 Ryzen 桌面 CPU 有较好的支持, ...

  9. Git练习3 远程库分支 idea中状态条显示当前分支

  10. HTTP header parsing errors will be logged at DEBUG level

    -- ::-exec-] INFO org.apache.coyote.http11.Http11Processor - Error parsing HTTP request header Note: ...