sqlcipher 数据库解密
使用 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 keyshould generally be called as the first operation on a database.
sqlcipher 数据库解密的更多相关文章
- 【iOS】FMDB/SQLCipher数据库加解密,迁移
2016-04-19更新:本文代码可能有些问题,请移步 http://zhengbomo.github.io/2016-04-18/sqlcipher-start/ 查看 sqlite应用几乎在所有的 ...
- Ubuntu下编译SqlCipher以及解密微信数据库EnMicroMsg.db过程和坑
wget https://codeload.github.com/sqlcipher/sqlcipher/zip/v3.4.2 ./configure --enable-tempstore=yes C ...
- Android数据存储之SQLCipher数据库加密
前言: 最近研究了Android Sqlite数据库(文章地址:Android数据存储之Sqlite的介绍及使用)以及ContentProvider程序间数据共享(Android探索之ContentP ...
- Android 天猫apk聊天数据库解密
1.使用Android 天猫apk 进行聊天会产生tmallWangXinDB的数据库.2.用sqlite3 工具打开提示加密或者错误.3.需要对该数据库进行解密. 解密流程:1.反编译apk,dex ...
- ios开发FMDB导入SQLCipher加密数据库
转:http://www.2cto.com/kf/201407/315727.html [iOS]FMDB/SQLCipher数据库加解密,迁移
- iOS SQLite解密之SQLCipher
开门见山,本文主要讲在Mac下使用SQLCipher编译解密数据库文件方法,iOS项目集成SQLCipher自己可以百度,网上帖子很多. 官方集成文档:https://www.zetetic.net/ ...
- iOS Sqlite加密(FMDB/SQLCipher)
/** * 对数据库加密 * * @param path path description * * @return return value description */ + (BOOL)encryp ...
- 日常破解--从XCTF的app3题目简单了解安卓备份文件以及sqliteCipher加密数据库
一.题目来源 题目来源:XCTF app3题目 二.解题过程 1.下载好题目,下载完后发现是.ab后缀名的文件,如下图所示: 2.什么是.ab文件?.ab后缀名的文件是Andr ...
- SQLite学习笔记(十)&&加密
随着移动互联网的发展,手机使用越来越广泛,sqlite作为手机端存储的一种解决方案,使用也非常普遍.但是sqlite本身安全特性却比较弱,比如不支持用户权限,只要能获取到数据库文件就能进行访问:另外也 ...
随机推荐
- Python open操作文件
操作文件 # coding=utf-8 支持中文 """ China Japan France England """ f = open(& ...
- isnull和sum的关系
这是我刚刚写存储过程的时候意识到的一个问题!!! 先问大家这样一个问题,print 100+null 等于多少? 在一组数据统计的过程中,只要使用到sum函数,就必须使用isnull函数包含起来,因 ...
- webpack踩坑之路 (2)——图片的路径与打包
刚开始用webpack的同学很容易掉进图片打包这个坑里,比如打包出来的图片地址不对或者有的图片并不能打包进我们的目标文件夹里(bundle).下面我们就来分析下在webpack项目中图片的应用场景. ...
- 第 2 章 容器架构 - 008 - Docker 组件如何协作?
容器启动过程如下: Docker 客户端执行 docker run 命令. Docker daemon 发现本地没有 httpd 镜像. daemon 从 Docker Hub 下载镜像. 下载完成, ...
- (转)c# 互斥锁
----------------------------------------------文章1---------------------------------------------- 互斥锁( ...
- [Spring] Annotation注释
自动扫描: 在<beans>标签内, <context:annotation-config />允许使用注解 <context:component-scan base-p ...
- C语言转义字符基础总结
C语言转义字符总结 C语言中的转义字符,是字符常量中很特别的一类.初学者容易在这方面犯错误,比如说我. 错题1 答案:C解析:每一个转义字符具有一个长度,这个字符串中:\t, \x43, \', \ ...
- English trip M1 - AC3 Teacher:Corrine
课堂上内容 16,black,games The clothes is Only $. is lucky number in China. God give us black eyes,but we ...
- 微信小程序发起微信支付
点击链接查看详情:(支付中配置参数需要从后台得到->签名需要从微信申请才可以得到) https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-pay.h ...
- php 路途一点启示
wo: 面试了很多说后台不适合女孩,我不相信,而且我还很笨 he:不是立马就能让别人认可你,其中过程要经历很多得,有时候也要换个方式的'' wo: 我只是想用学的知识得到实践 he:那学习的过程不是 ...