安装
sqlcipher
命令
,
首先需要安装
brew
1.
在终端输入
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
,按
Enter
键继续
2. 提示
“
Press RETURN to continue or any other key to abort
”
时,按
Enter
键继续
3. 提示
”Password”
时,输入当前用户开机密码,按
Enter
键继续
4. 等待安装成功之后在终端在运行
brew install sqlcipher
解密目标数据库xxxxx
.db
,123456为数据库密码,解密后的数据库为
plaintext.db
1.
使用终端切换到数据库的路径下,命令 cd /Users/xxxxxxx 或 cd (拖动数据库所在文件夹到终端),按
Enter
键继续
2. 切换到数据库所在文件夹之后,输入
sqlcipher
xxxxx
.db
,按
Enter
键继续
3. 提示“
Enter SQL statements terminated with a ";"
” 时,
输入
PRAGMA key = '
123456
';
按
Enter
键继续
4. 输入
ATTACH DATABASE 'plaintext.db' AS plaintext KEY '';
按
Enter
键继续
5.
输入
SELECT sqlcipher_export('plaintext');
按
Enter
键继续
6. 输入
DETACH DATABASE plaintext;
7.
生成的
plaintext.db
即为解密后的数据库,可直接打开
//==================================================================================================================
以下为原文,可以忽略
转载自:http://blog.csdn.net/majiakun1/article/details/46551137
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操作。最后用
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
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.
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';
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'";
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
PRAGMA key should generally be called as the first operation on a database.
步骤归纳:以下为原文,可以忽略转载自:http://blog.csdn.net/majiakun1/article/details/46551137一. 1.安装sqlcipher命令,首先需要安装brew, 在终端输入 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/
下载之后,编译
$ ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto -L/usr/local/opt/openssl/lib" CPPFLAGS="-I/usr/local/opt/openssl/include"
$ make
利用sqlci
在嵌入式上使用QT开发用户界面时候,少不了使用数据库。但是Qt自带的sqlite3数据库是没有加密的,因此当保存一些敏感信息的时候很容易暴漏个人隐私。网上查了很多资料,此处做下总结方便大家学习。
1.加密方式分类
1.1)使用SQLCipher加密。
1.2)使用wxSqlite加密。
2.使用wxSqlite加密步骤
2.1)下载并解压文件
下载地址:Releases · utelle/wxsqlite3 · GitHub
此处我下载的是3-4.5.1,解压后如下:
由于文件众..
怕原作者生气,在这就不放源代码了。
最近研究“给力大CI典”的时候,反汇编了一下,是用DELPHI写的,使用SQLITE3定制版本加密了一部分数据库,于是通过HOOKAPI到sqlite3_key,找到了密码,然后用VB6写了个解密SQLITE3的工具,把数据库都解密了。
这里就给出两个密钥:
1、shao8977545*S
用于zclb.db。
2、shao897754*Z
用于其余...
用了ADO.NET 2.0 SQLite Data Provider 这样可以直接利用它来创建一个加密的sqlite数据库。<br />有关c#代码如下:<br />1、创建空的sqlite数据库。
//数据库名的后缀你可以直接指定,甚至没有后缀都可以<br />//方法一:创建一个空sqlite数据库,用IO的方式<br />FileStream fs = File.Create(“c://test.db“);<br />//方法二:用SQLiteConnection<br />SQLiteConnec
Android中的SQLite数据库是一种轻量级的数据库,它可以在Android应用程序中存储和检索数据。SQLite数据库使用SQL语言来管理数据,可以在Android应用程序中创建、读取、更新和删除数据。使用SQLite数据库可以使应用程序更加高效和可靠,因为它可以在本地存储数据,而不需要访问网络。在Android中使用SQLite数据库需要使用SQLiteOpenHelper类来创建和管理数据库。SQLiteOpenHelper类提供了一些方法来创建和升级数据库,以及插入、查询、更新和删除数据。在使用SQLite数据库时,需要注意数据类型、表结构、SQL语句等方面的问题,以确保数据的正确性和完整性。