sqlcipher加密原理_sqlserver数据库加密

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

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 通讯协议与即时通讯[通俗易懂]

    通讯协议与即时通讯[通俗易懂]通讯协议与即时通讯

    2022年4月23日
    72
  • MATLAB之fprintf函数的具体使用方法

    MATLAB之fprintf函数的具体使用方法fprintf函数可以将数据按指定格式写入到文本文件中。其调用格式为:数据的格式化输出:fprintf(fid,format,variables)按指定的格式将变量的值输出到屏幕或指定文件fid为文件句柄,若缺省,则输出到屏幕format用来指定数据输出时采用的格式%d整数%e实数:科学计算法形式%f实数:小数形式%g由系统自动选取上述两种格式之一%s输出字符串fprintf(fid,forma…

    2022年10月19日
    2
  • oracle数据库添加用户至dba_oracle取消用户dba权限

    oracle数据库添加用户至dba_oracle取消用户dba权限首先用管理员身份进入数据库SQLPLUSSYSTEM/密码sqlplussystem/diwaycom创建用户CREATEUSER用户名IDENTIFIEDBY密码;createuserdiwayidentifiedbydiwaycom;将刚创建的用户解锁ALTERUSER用户名ACCOUNTUNLOCK/LOCK;Alteruserdiwayaccount…

    2022年9月26日
    2
  • 质数域的算数运算[通俗易懂]

    质数域的算数运算[通俗易懂]本文介绍了在质数域FpF_pFp​中的算数运算执行算法。包括任意质数p的算法,当模数p具有特性形式时,该算法揭示约化步骤的执行效率能够获得提升;还提出了针对NIST质数的高效约化算法,对诸如p=2192−264−1p=2^{192}-2^{64}-1p=2192−264−1形式的质数具有适用性。本文提出的算法尤适合软件执行。假设工作台通常为64位或32位,算法运行在WWW-位(W-位,W是8的倍数)框架基础上。低位或更廉价的组件的W值更小,比如嵌入式系统一般是16位,智能卡一般是8位。W-位的位数词U从0

    2025年5月30日
    2
  • ThreadPoolExcutor(线程池)

    ThreadPoolExcutor(线程池)1、概念:   用于管理java的多线程。线程的生命周期包括创建、就绪、运行、阻塞、销毁,当有大量的线程任务需要创建时,内存的开销就大了,此时,使用线程池,在一定程度上能够很好的缓解线程的大开销。2、优势:    (1)降低资源消耗。通过重复利用已创建的线程降低线程创建、销毁线程造成的消耗。   (2)提高响应速度。当任务到达时,任务可以不需要等到线程

    2025年7月11日
    6
  • redis端口号为什么是6379「建议收藏」

    redis端口号为什么是6379「建议收藏」6379在是手机按键上MERZ对应的号码,而MERZ取自意大利歌女AlessiaMerz的名字。MERZ长期以来被Redis作者antirez及其朋友当作愚蠢的代名词。后来Redis作者在开发Redis时就选用了这个端口。——AlessiaMerz是一位意大利舞女、女演员。Redis作者Antirez早年看电视节目,觉得Merz在节目中的一些话愚蠢可笑,Antirez喜欢造…

    2022年5月30日
    231

发表回复

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

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