├── .gitignore ├── .npmignore ├── README.md ├── bower.json ├── index.js ├── package.json ├── platform └── electron │ └── windows │ └── libeay32 │ ├── x64 │ └── libeay32.dll │ └── x86 │ └── libeay32.dll └── postinstall.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .npmrc 3 | npm-debug.log 4 | node_modules 5 | .idea -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .npmrc 3 | npm-debug.log 4 | node_modules 5 | .idea -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sqlcipher 2 | > sqlcipher 是一个基于openssl加密功能sqlite3。形式上增加一些与加密功能相关`sql`语句;本质上是一个经过重新编译的sqlite3,不破坏原有功能,仅仅增添了加密特性。 3 | 4 | ### 简介 5 | SQLCipher是开源SQLite的一个扩展,此处不是作为SQLite插件,而是指扩展其功能,扩展[sqlite API](https://github.com/mapbox/node-sqlite3/wiki/API),因为SQLCipher需要重新编译SQLite,最终生成一个集成加密功能的`node_sqlit3.node`node文件。SQLCipher对**整个数据库文件加密**。SQLCipher安装不需要复杂的配置环境,一般系统有`npm`就可以针对一些环境进行安装,在过程中会自动安装构建的依赖项。与加密功能的sql语句往往放置最前面,一般是连接数据库之后,就执行这些语句。 6 | 7 | ### 支持平台 8 | * C/C++ 9 | * Obj-C 10 | * QT 11 | * Win32/.NET 12 | * Java 13 | * Python 14 | * Ruby 15 | * Linux 16 | * Mac OS X 17 | * iPhone/IOS 18 | * Android 19 | * Xamarin.IOS 20 | * Xamarin.Android 21 | * Electron 22 | 23 | 24 | 25 | ### 用法 26 | 27 | ```javascript 28 | var SQLite3 = require('sqlcipher').verbose(); 29 | var sqlite = new SQLite3.Database('./test-win.db'); 30 | 31 | sqlite.run("pragma key = 'secret'"); 32 | sqlite.run("pragma cipher = 'aes-256-cbc'");//optional, default cipher be eqaul to 'aes-256-cbc' 33 | ``` 34 | 注意:sqlcipher该插件是在sqlite3的基础上增添了加密功能。因此,使用sqlcipher可以对数据库文件进行加密或不加密。如果要对数据库文件进行加密,则连接(创建)数据库文件后,第一条`sql`语句必须是`pragma key = '...'`,否则将会出现意想不到的错误。 35 | 36 | ### 安装 37 | ```bash 38 | npm install sqlcipher 39 | ``` 40 | 通过运行以上命令,将会根据系统的环境编译出相应(系统下node版本以及node位数)的sqlciher。默认支持以下三种系统环境。 41 | 42 | - windows 43 | - mac 44 | - linux 45 | 46 | 通过携带参数可以在指定环境下进行编译。[特定环境安装](https://github.com/zhouchangsheng/sqlcipher/wiki/%E5%AE%89%E8%A3%85) 47 | ```bash 48 | npm install sqlcipher --target=`目标运行环境版本号` --target_arch=`目标运行环境位数` --dist-url=`目标运行环境下载地址` --runtime=`目标运行环境` 49 | ``` 50 | 51 | 52 | ### 加密算法 53 | sqlcipher基于openssl加密库,支持多种加密算法,在实际开发中可以使用默认算法aes-256-cbc或者在[支持的加密算法](https://github.com/zhouchangsheng/sqlcipher/wiki/%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95)中选择其中某一个。 54 | * aes-128-cbc 55 | * aes-192-cfb 56 | * aes-256-cbc(默认) 57 | * cast 58 | * rc4 59 | 60 | ### API 61 | sqlcipher 常用api有指定加密秘钥、指定加密算法、更换秘钥等。当然,如果需要改善加密环境下的sqlite性能,有更详细的[api](https://www.zetetic.net/sqlcipher/sqlcipher-api/)(即`sql`语句)去优化项目。 62 | 63 | 1.加密秘钥 64 | ```bash 65 | pragma key = 'secret'; 66 | ``` 67 | 68 | 2.加密算法 69 | 70 | ```bash 71 | pragma cipher = 'aes-128-cbc'; 72 | ``` 73 | 74 | 3.更换秘钥 75 | 76 | ```bash 77 | pragma rekey = 'aes-128-cbc'; 78 | ``` 79 | 80 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sqlcipher", 3 | "version": "1.1.1", 4 | "description":"", 5 | "homepage": "https://zhouchangsheng.github.io", 6 | "main": [ 7 | "./lib/index.js" 8 | ], 9 | "ignore": [ 10 | "**/.*", 11 | "Gruntfile.js", 12 | "MAINTAIN.md", 13 | "grunts", 14 | "node_modules", 15 | "bower_components", 16 | "test" 17 | ] 18 | } -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | module.exports = require('sqlite3') 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sqlcipher", 3 | "version": "1.1.1", 4 | "main":"index.js", 5 | "description": "SQLCipher is a sqlite3 with encryption based on openssl(SQLCipher 是一个基于openssl加密功能sqlite3)", 6 | "scripts": { 7 | "postinstall": "node postinstall" 8 | }, 9 | "repository":{ 10 | "type":"git", 11 | "url":"https://github.com/zhouchangsheng/sqlcipher.git" 12 | }, 13 | "keywords": [ 14 | "sqlite3", 15 | "sqlite", 16 | "sqlcipher", 17 | "encrypt" 18 | ], 19 | "bugs":{ 20 | "url":"https://github.com/zhouchangsheng/sqlcipher/issues" 21 | }, 22 | "dependencies": { 23 | "shelljs": "^0.7.4", 24 | "sqlite3": "git+https://github.com/zhouchangsheng/node-sqlite3.git#openssl-root" 25 | }, 26 | "license": "ISC", 27 | "author": { 28 | "name":"jerry_zhou(zhou chang sheng)", 29 | "email":"zcs1041883243@gmail.com" 30 | }, 31 | "maintainers":[ 32 | { 33 | "name":"jerry_zhou(zhou chang sheng)", 34 | "email":"zcs1041883243@gmail.com" 35 | } 36 | ], 37 | "homepage":"https://github.com/zhouchangsheng/sqlcipher" 38 | } 39 | -------------------------------------------------------------------------------- /platform/electron/windows/libeay32/x64/libeay32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhouchangsheng/sqlcipher/5c1f6f4985f6f8167422c6fdbb97236a6de50b51/platform/electron/windows/libeay32/x64/libeay32.dll -------------------------------------------------------------------------------- /platform/electron/windows/libeay32/x86/libeay32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhouchangsheng/sqlcipher/5c1f6f4985f6f8167422c6fdbb97236a6de50b51/platform/electron/windows/libeay32/x86/libeay32.dll -------------------------------------------------------------------------------- /postinstall.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | require('shelljs/global') 3 | var isArray = require('util').isArray 4 | 5 | var args 6 | try { 7 | args = JSON.parse(process.env.npm_config_argv).original 8 | } finally { 9 | if (!isArray(args)) { 10 | args = [] 11 | } 12 | } 13 | var targetArgs = args.filter(function (arg) { 14 | return /^--(runtime|target)/.test(arg) 15 | }) 16 | var targetStr = targetArgs.reduce(function (m, arg) { 17 | return m + ' ' + arg 18 | }, '') 19 | 20 | if(process.platform === 'win32'){ 21 | // windows 22 | // todo: pass build args 23 | // exec('npm install sqlite3 --build-from-source' + targetStr) 24 | cd('node_modules/sqlite3') 25 | exec('npm i --build-from-source' + targetStr) 26 | }else{ 27 | // not windows 28 | if (process.platform === 'darwin') { 29 | // macos 30 | if (exec('which brew').stdout.trim() === '') { 31 | console.error('`brew` is required to be installed.') 32 | exit(1) 33 | } 34 | if (exec('brew list sqlcipher').code !== 0) { 35 | // exec('brew install sqlcipher') 36 | exec('brew install sqlcipher --with-fts') 37 | } 38 | exec('export LDFLAGS="-L`brew --prefix`/opt/sqlcipher/lib"') 39 | exec('export CPPFLAGS="-I`brew --prefix`/opt/sqlcipher/include"') 40 | cd('node_modules/sqlite3') 41 | exec('npm i --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix`' + targetStr) 42 | } else { 43 | // linux 44 | exec('export LDFLAGS="-L/usr/local/lib"') 45 | exec('export CPPFLAGS="-I/usr/local/include -I/usr/local/include/sqlcipher"') 46 | exec('export CXXFLAGS="$CPPFLAGS"') 47 | cd('node_modules/sqlite3') 48 | exec('npm i --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/local --verbose' + targetStr) 49 | } 50 | } 51 | 52 | --------------------------------------------------------------------------------