SQLCipher 是用来加密数据库
一.
1.安装sqlcipher命令,首先需要安装brew, 在终端输入
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
成功之后在终端在运行
brew install sqlcipher
二.
1. 创建加密数据库
$ sqlcipher encrypted.db
SQLCipher version 3.8.4.3 2014-04-03 16:53:12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> PRAGMA key = 'thisiskey';
sqlite> create table encrypted (id integer, name text);
sqlite> .schema
CREATE TABLE encrypted (id integer, name text);
sqlite> .q
2. 打开加密数据库
$ sqlcipher encrypted.db
SQLCipher version 3.8.4.3 2014-04-03 16:53:12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> PRAGMA key = 'thisiskey';
sqlite> .schema
CREATE TABLE encrypted (id integer, name text);
3. 修改数据库密码
sqlite> PRAGMA rekey = 'newkey';
4. 加密已有的数据库
$ sqlcipher banklist.sqlite3
SQLCipher version 3.8.4.3 2014-04-03 16:53:12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'thisiskey';
sqlite> SELECT sqlcipher_export('encrypted');
sqlite> DETACH DATABASE encrypted;
5. 解密数据库
$ sqlcipher encrypted.db
SQLCipher version 3.8.4.3 2014-04-03 16:53:12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> PRAGMA key = 'thisiskey';
sqlite> ATTACH DATABASE 'plaintext.db' AS plaintext KEY '';
sqlite> SELECT sqlcipher_export('plaintext');
sqlite> DETACH DATABASE plaintext;
转自 : http://my.oschina.net/kjpioo/blog/149290
satckoverflow.com上有人提到过在
sqlite> sqlcipher-shell32.exe test.db
sqlite> PRAGMA KEY = '12345';
给刚打开的数据库设置密码后,马上接着往数据库执行create table和 insert操作。最后用