SQLCipher的使用

本文介绍了如何使用SQLCipher对SQLite数据库进行加密和解密,包括创建加密数据库、打开加密数据库、修改数据库密码、加密已有数据库和解密数据库的步骤。强调了在操作加密数据库时必须先设置PRAGMA KEY的重要性,以及提供了两种设置密钥的方法:使用Passphrase和Raw Key Data。
摘要由CSDN通过智能技术生成

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操作。最后用

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值