使用 sqlcipher.exe 可以在输入密码后,查看加密数据库的内容。

但是要编码查询数据库的内容,还要另寻方法。(相关的工具和库在我的百度网盘中)

使用sqlcipher windows 命令工具

注意 使用的工具也分版本,要与加密数据库的版本对应起来,否则查看不到表

下载地址:

对应2.x

http://download.csdn.net/detail/zhanghw0917/7931759

3.01版本

http://download.csdn.net/detail/zhanghw0917/7931909

转载 http://www.cnblogs.com/treecat-roboto/p/3873707.html

加密后使用命令行还是可以查看滴

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. 解密数据库(生成无密码的数据库: plaintext.db)
$ sqlcipher-shell32 encrypted.db

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

sqlite> .e

退出该数据库。但是下次再用

sqlite> sqlcipher-shell32.exe  test.db

登录,在输入密码前执行了.schema等其他操作

sqlite>.schema

Error: file is encrypted or is not a database

sqlite> PRAGMA KEY = '12345';

Error: file is encrypted or is not a database

遭到提示:Error: file is encrypted or is not a database

根据官方以上英文描述,这个问题就是因为操作上没有遵循just-in-time key derivation的要求,没有首先输密码解密再进行其他操作。

有图为证:

----------------以下为正确操作过程:

SQLite version 3.7.15.2 2013-01-09 11:53:05
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> PRAGMA KEY = '12345';
sqlite> .schema
CREATE TABLE t(name text);
sqlite> select * from t;
n1
sqlite>

----------------以下为错误操作过程:

Enter SQL statements terminated with a ";"
sqlite> .schema
Error: file is encrypted or is not a database
sqlite> PRAGMA KEY = '12345';
sqlite> .schema
Error: file is encrypted or is not a database
sqlite>

确实如此。

以上过程你可以自己亲自验证以下。

注意:通过命令行( sqlcipher-shell32.exe) 执行命令,与通过sqlite3 api调用操作sqlite3数据库,是一样的道理

参考:

https://www.zetetic.net/sqlcipher/sqlcipher-api/#key

PRAGMA key

The process of creating a new, encrypted database is called “keying” the database. SQLCipher uses just-in-time key derivation at the point it is first needed for an operation. This means that the key (and any options) must be set before the first operation on the database. As soon as the database is touched (e.g. SELECT, CREATE TABLE, UPDATE, etc.) and pages need to be read or written, the key is prepared for use.

Example 1: Passphrase with Key Derivation

The key itself can be a passphrase, which is converted to a key using PBKDF2 key derivation. The result is used as the encryption key for the database.

sqlite> PRAGMA key = 'passphrase';

Example 2: Raw Key Data (Without Key Derivation)

Alternatively, it is possible to specify an exact byte sequence using a blob literal. With this method, it is the calling application's responsibility to ensure that the data provided is a 64 character hex string, which will be converted directly to 32 bytes (256 bits) of key data.

sqlite> PRAGMA key = "x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'";

Testing the Key

When opening an existing database, PRAGMA key will not immediately throw an error if the key provided is incorrect. To test that the database can be successfully opened with the provided key, it is necessary to perform some operation on the database (i.e. read from it) and confirm it is success.

The easiest way to do this is select off the sqlite_master table, which will attempt to read the first page of the database and will parse the schema.

sqlite> PRAGMA key = 'passphrase';
sqlite> SELECT count(*) FROM sqlite_master; -- if this throws an error, the key was incorrect. If it succeeds and returns a numeric value, the key is correct;

The same check can be implemented in C code

sqlite3_key(database, "test123", 7);
if (sqlite3_exec(database, "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) {
// key is correct.
} else {
// key is incorrect
}

Implementation Notes

  • PRAGMA key should generally be called as the first operation on a database.

sqlcipher 数据库解密的更多相关文章

  1. 【iOS】FMDB/SQLCipher数据库加解密,迁移

    2016-04-19更新:本文代码可能有些问题,请移步 http://zhengbomo.github.io/2016-04-18/sqlcipher-start/ 查看 sqlite应用几乎在所有的 ...

  2. Ubuntu下编译SqlCipher以及解密微信数据库EnMicroMsg.db过程和坑

    wget https://codeload.github.com/sqlcipher/sqlcipher/zip/v3.4.2 ./configure --enable-tempstore=yes C ...

  3. Android数据存储之SQLCipher数据库加密

    前言: 最近研究了Android Sqlite数据库(文章地址:Android数据存储之Sqlite的介绍及使用)以及ContentProvider程序间数据共享(Android探索之ContentP ...

  4. Android 天猫apk聊天数据库解密

    1.使用Android 天猫apk 进行聊天会产生tmallWangXinDB的数据库.2.用sqlite3 工具打开提示加密或者错误.3.需要对该数据库进行解密. 解密流程:1.反编译apk,dex ...

  5. ios开发FMDB导入SQLCipher加密数据库

    转:http://www.2cto.com/kf/201407/315727.html [iOS]FMDB/SQLCipher数据库加解密,迁移

  6. iOS SQLite解密之SQLCipher

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

  7. iOS Sqlite加密(FMDB/SQLCipher)

    /** * 对数据库加密 * * @param path path description * * @return return value description */ + (BOOL)encryp ...

  8. 日常破解--从XCTF的app3题目简单了解安卓备份文件以及sqliteCipher加密数据库

    一.题目来源     题目来源:XCTF app3题目 二.解题过程     1.下载好题目,下载完后发现是.ab后缀名的文件,如下图所示:     2.什么是.ab文件?.ab后缀名的文件是Andr ...

  9. SQLite学习笔记(十)&&加密

    随着移动互联网的发展,手机使用越来越广泛,sqlite作为手机端存储的一种解决方案,使用也非常普遍.但是sqlite本身安全特性却比较弱,比如不支持用户权限,只要能获取到数据库文件就能进行访问:另外也 ...

随机推荐

  1. 给大一新生学习c程序的一些建议的一些建议

    这是一篇给刚学习c程序的学弟们的一篇日志.如果想学好c程序,以及不想走太多弯路,希望能看一下这篇文章,如果说基础较好,或者说已经是大二,大三,这篇文章不会有什么帮助. 刚转到软件工程系,加了几个新生群 ...

  2. STL_string.ZC

    1.转成 小写/大写 #include <algorithm>using namespace std; // 转成小写transform(_strAttrNameG.begin(), _s ...

  3. Excel 常用设置

    首行固定 视图->冻结窗口

  4. 从flask视角理解angular(四)Route

    app-routing.modules.ts import { NgModule } from '@angular/core'; import { RouterModule, Routes } fro ...

  5. QTableWidget自定义表头QHeaderView加全选复选框

    1         QTableWidget自定义表头QHeaderView加全选复选框 在使用QTableWidget时需要在表头添加全选复选框,但是默认的表头无法添加复选框,只能用图片画上去一个复 ...

  6. Codeforces E - Connected Components?

    E - Connected Components? 思路: 补图bfs,将未访问的点存进set里 代码: #include<bits/stdc++.h> using namespace s ...

  7. C# 连接PDA扫码枪

    Symbol扫码枪开发文档 一.主要功能 实现symbol扫码枪和PC数据交互. 二.运行环境 SymbolMC32NO 三.开发工具与软件 开发环境:Win7 开发语言:C# 数据库:Sql Ser ...

  8. ERROR org.redisson.client.handler.CommandDecoder - Unable to decode data. channel

    一.异常出现的场景 某一天下午,测试突然跑过来说,IOS系统APP访问500,Android没问题.我的第一反应是那就奇怪了,调的接口都是一样的,莫非和系统有关系.而且这个错误重启服务后,过一段时间才 ...

  9. LeetCode--459--重复的字符串

    问题描述: 给定一个非空的字符串,判断它是否可以由它的一个子串重复多次构成.给定的字符串只含有小写英文字母,并且长度不超过10000. 示例 1: 输入: "abab" 输出: T ...

  10. 赵炯博士《Linux内核完全注释》

    赵炯:男,1963年10月5日出生,江苏苏州人,汉族. 同济大学机械工程学院机械电子教研室副教授,从事教学和科研工作. 现在主要为硕士和博士研究生开设<计算机通信技术>.<计算机控制 ...