当前位置:   article > 正文

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

使用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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/492423
推荐阅读
相关标签
  

闽ICP备14008679号