pysqlcipher java,sqlite3 用SQLCipher 加密后 命令行下如何重新打开和读取

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.

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数据库,是一样的道理

本人文章除注明转载外,均为本人原创或编译

欢迎任何形式的转载,但请务必注明出处,尊重他人劳动共创开源社区

转载请注明:文章转载自:开源中国社区[http://www.oschina.net]

本文标题:sqlite3 用SQLCipher 加密后 命令行下如何重新打开和读取

本文地址:http://my.oschina.net/kjpioo/blog/149290

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值