sqlcipher加密原理_sqlserver数据库加密

sqlcipher加密原理_sqlserver数据库加密使用 sqlcipher.exe可以在输入密码后,查看加密数据库的内容。但是要编码查询数据库的内容,还要另寻方法。(相关的工具和库在我的百度网盘中)使用sqlcipherwindow


Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

使用 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.
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/166996.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • c++将十进制数转化为二进制数_十六进制小数转二进制

    c++将十进制数转化为二进制数_十六进制小数转二进制#include"stdafx.h"#include<iostream>#include<math.h>usingnamespacestd;voidchange(doublex);voidchange(doublex){ doublen=0;…

    2022年9月24日
  • 除了we tool还有哪些免费安全好用的微信群发软件?这两个软件比we tool好用!

    除了we tool还有哪些免费安全好用的微信群发软件?这两个软件比we tool好用!除了wetool还有哪些安全好用的微信群发软件?群发工具是社群运营使用频率最高的工具,无论是给群内推送消息,还是给个人推送消息。按键精灵:点击左侧链接下载按键精灵是一款模拟鼠标键盘动作的软件。通过制作脚本,可以让按键精灵代替您的双手,自动执行一系列鼠标键盘动作。按键精灵免费版简单易用,不需要任何编程知识就可以作出功能强大的脚本。只要您在电脑前用双手可以完成的动作,按键精灵都可以替您完成。按键精灵用途广泛,具有大量脚本资源。简单百宝箱:点击左侧链接下载简单百宝箱是一个绿色和安全的游戏

    2022年6月4日
  • 单片机结构_单片机原理读书笔记

    单片机结构_单片机原理读书笔记文章目录Chapter1:51单片机结构1.1MCS-51单片机内部结构1.1.151单片机内部结构1.1.2核心部件CPU1.2存储器1.2.1ROM和RAM1.2.2普林斯顿结构、哈佛结构1.2.3片内存储器、片外存储器1.2.4程序存储器、外部数据、内部数据存储器1.3特殊功能寄存器1.4时钟电路和复位电路1.4.1时钟电路1.4.2基本时序单位1.4.3复位…

    2022年10月4日
  • 解决SqlTransaction用尽的问题(SQL处理超时)

    解决SqlTransaction用尽的问题(SQL处理超时)有时候程序处理的数据量比较小时,四平八稳,一切安然无恙,但数据量一大,原先潜伏的问题就暴露无遗了。原访问数据库的代码为: 1SqlConnection conn = new SqlConnection(strConn); 2conn.Open(); 3SqlTransaction trans = conn.BeginTransaction(); 4try 5{ 6    CEngine.Exe…

    2022年5月18日
  • java学习——java面试【事务、锁、多线程】资料整理

    成长之路,一起走!总结一些知识,方面自己学习,也方面热爱学习的伙伴们可以更好的成长! 项目直接是静态的Html,下载后可以直接访问! 地址:https://github.com/dufyun/kuyu/tree/master/kuyuTechHtml

    2022年2月25日
  • MySQL为什么用B+树,而不用B树?

    MySQL为什么用B+树,而不用B树?

    2022年2月19日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号