Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法在命令行sqlcipher工具中打开pysqlcipher加密字典_Python_Sqlite_Sqlcipher_Pysqlcipher - Fatal编程技术网

Python 无法在命令行sqlcipher工具中打开pysqlcipher加密字典

Python 无法在命令行sqlcipher工具中打开pysqlcipher加密字典,python,sqlite,sqlcipher,pysqlcipher,Python,Sqlite,Sqlcipher,Pysqlcipher,我可以使用创建一个加密数据库,并使用pysqlcipher打开它,但在从源代码安装sqlcipher时,我无法使用Mac OS X上安装的sqlciphercommand0line工具打开同一个数据库。对于安装,我遵循这里列出的步骤:因此,在这两种情况下,libsqlcipher的版本应该是相同的 测试脚本 from pysqlcipher import dbapi2 as sqlite conn = sqlite.connect('test.db') c = conn.cursor() c.e

我可以使用创建一个加密数据库,并使用pysqlcipher打开它,但在从源代码安装sqlcipher时,我无法使用Mac OS X上安装的
sqlcipher
command0line工具打开同一个数据库。对于安装,我遵循这里列出的步骤:因此,在这两种情况下,
libsqlcipher
的版本应该是相同的

测试脚本

from pysqlcipher import dbapi2 as sqlite
conn = sqlite.connect('test.db')
c = conn.cursor()
c.execute("PRAGMA key='test'")
c.execute('''create table stocks (date text, trans text, symbol text, qty real, price real)''')
c.execute("""insert into stocks values ('2006-01-05','BUY','RHAT',100,35.14)""")
conn.commit()
c.close()


conn = sqlite.connect('test.db')
c = conn.cursor()
c.execute("PRAGMA key='test'")
c.execute("SELECT * FROM stocks;")
print(c.fetchall())
c.close()
$ python ciphertest.py
[(u'2006-01-05', u'BUY', u'RHAT', 100.0, 35.14)]
输出

from pysqlcipher import dbapi2 as sqlite
conn = sqlite.connect('test.db')
c = conn.cursor()
c.execute("PRAGMA key='test'")
c.execute('''create table stocks (date text, trans text, symbol text, qty real, price real)''')
c.execute("""insert into stocks values ('2006-01-05','BUY','RHAT',100,35.14)""")
conn.commit()
c.close()


conn = sqlite.connect('test.db')
c = conn.cursor()
c.execute("PRAGMA key='test'")
c.execute("SELECT * FROM stocks;")
print(c.fetchall())
c.close()
$ python ciphertest.py
[(u'2006-01-05', u'BUY', u'RHAT', 100.0, 35.14)]
这一部分正如预期的那样。
hextump
的输出还确认数据库实际上是加密的:

$ hexdump -C test.db
00000000  65 17 e3 50 08 b6 5c 94  d5 18 10 f1 61 cc 4f 04  |e..P..\.....a.O.|
00000010  18 02 37 43 15 fc 17 b9  36 e4 3c 55 0a 95 db 80  |..7C....6.<U....|
00000020  37 6e f3 71 97 7e 69 e7  61 81 33 c7 24 68 80 80  |7n.q.~i.a.3.$h..|
00000030  32 b1 b0 27 6a 19 22 31  50 29 16 96 48 9b 63 16  |2..'j."1P)..H.c.|
00000040  e2 6a de 7b c8 0b 1d bf  ba 48 29 6c 41 4d 73 36  |.j.{.....H)lAMs6|
00000050  24 19 25 11 66 60 5d 89  e6 d6 d3 07 66 d2 7a 34  |$.%.f`].....f.z4|
00000060  c3 7b f8 e4 3f 41 d2 3c  ab 28 fb 65 9c 6d 88 e2  |.{..?A.<.(.e.m..|
00000070  3f 4a d7 e3 89 50 04 e7  24 36 64 a8 49 65 88 db  |?J...P..$6d.Ie..|
作为最后一个测试,我使用相同的密钥从sqlcipher命令行工具创建了一个加密数据库。我希望该数据库与Python脚本创建的数据库完全相同(这是合理的期望吗?可能会有所不同):

hexdump确认它们不相同:

$ hexdump -C test2.db
00000000  9e 08 4c 64 cb 31 05 b0  f7 73 ce 96 9a 22 72 1c  |..Ld.1...s..."r.|
00000010  7f 3f 59 a6 58 7f 5b ff  18 b1 86 03 93 4d f4 8b  |.?Y.X.[......M..|
00000020  08 41 66 16 67 a4 cf d8  e3 7d c0 ca 62 df 3f 37  |.Af.g....}..b.?7|
00000030  82 82 65 10 f6 69 a4 68  25 cb c7 32 33 4c 89 70  |..e..i.h%..23L.p|
00000040  1d d9 fe 4d ae eb 73 67  77 13 c9 a5 3e 5e ad a6  |...M..sgw...>^..|
00000050  77 dc b9 62 63 ed f5 41  ad 93 d7 08 11 d7 9e 4f  |w..bc..A.......O|
00000060  85 55 e7 2e 2a e8 8e 46  e0 4d 02 e2 75 ec c7 51  |.U..*..F.M..u..Q|
00000070  9d b7 9e 2a 91 b9 fd a7  de 2f 12 4b 2f 47 e5 cc  |...*...../.K/G..|

我不确定这是我自己的错误,还是
pysqlcipher
库的问题。我希望安全,但任何建议都将不胜感激

我做了一些与你类似的事情

在最新版本的sqlcipher(如3.1.0或3.3.0)中,它的cipher_default_kdf_iter是64000。 但是我的pysqlcipher的,也许和你的一样,是4000。 因此,您可以像这样执行sql “PRAGMA cipher\u default\u kdf\u iter=4000;” 在您的sqlcipher.exe中。 希望能对你有所帮助