Skip to main content

python version of sqlcipher

Project description

CryptoSqlite

正儿八经的sqlite3结合sqlcipher, 且符合dbapi2标准的python模块。 兼容各个python版本。

安装

本项目python版本要求>= 3.7, 支持Linux、Windows。已有预编译版本>=3.7 and <=3.12

源码安装

源码安装请确保网络能够流畅访问github

默认情况下, 会下载最新的sqlcipher进行编译安装, 如果需要指定版本, 确保在编译前设置环境变量SQLCIPHER_VERSION,如v4.6.1

如果系统已经存在sqlcipher, 请设置环境变量SQLCIPHER_INCLUDE_DIRSsqlite.h头文件位置,SQLCIPHER_LIBRARY_DIRSsqlcipher.liblibsqlcipher.a所在位置。

如果设置了SQLCIPHER_VERSION将会忽略SQLCIPHER_INCLUDE_DIRSSQLCIPHER_LIBRARY_DIRS环境变量

Windows

要求:

  • msvc 编译器
  • nmake
  • 如果python版本低于3.9, 需要确保系统安装了tclsh, 且在PATH环境变量中

Linux

要求:

  • gcc 编译器
  • make
  • libtool

示例

加密

key='123456'
exist_db = 'test.db3'
newdb = 'encrypt_db.db3'

conn = sqlite3.connect(exist_db)
cur = conn.cursor()
cur.execute(f"ATTACH DATABASE '{newdb}' AS encrypted KEY '{self.key}'")
cur.execute("SELECT sqlcipher_export('encrypted')")
cur.execute("DETACH DATABASE encrypted")
assert os.path.exists(newdb)

cur.close()
conn.close()

解密

key='123456'
encrypt_db = 'test.db3'

conn = sqlite3.connect(encrypt_db)
cur = conn.cursor()
cur.execute(f"PRAGMA key='{key}'") 
res = cur.execute("SELECT name FROM sqlite_master")
assert res.fetchone()[0] == 'movie'

cur.close()
conn.close()

导出为非加密db

olddbname = 'encrypt_xxx.db3'
plaindbname = 'plain_xxx.db3'
key = '123456'
con = sqlite3.connect(olddbname)

cur = con.cursor()
dbname = 'plaindb'
cur.execute(f"PRAGMA key='{key}'")
cur.execute(f"ATTACH DATABASE '{plaindbname}' AS {dbname} KEY ''")
cur.execute(f"SELECT sqlcipher_export('{dbname}')")
cur.execute(f"DETACH DATABASE {dbname}")
cur.close()
con.close()

# 判断是否导出成功
assert os.path.exists(plaindbname)

修改密码

dbname = 'dbtest.db3'
oldkey = '123456'
newkey = '654321'

conn = sqlite3.connect(dbname)
cur = conn.cursor()
cur.execute(f"PRAGMA key='{oldkey}'") 
cur.execute(f"PRAGMA rekey='{newkey}'") 
cur.close()
conn.close()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cryptosqlite-0.0.3.tar.gz (38.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

CryptoSqlite-0.0.3-cp312-cp312-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.12Windows x86-64

CryptoSqlite-0.0.3-cp312-cp312-manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

CryptoSqlite-0.0.3-cp311-cp311-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.11Windows x86-64

CryptoSqlite-0.0.3-cp311-cp311-manylinux_2_28_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

CryptoSqlite-0.0.3-cp310-cp310-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.10Windows x86-64

CryptoSqlite-0.0.3-cp310-cp310-manylinux_2_28_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

CryptoSqlite-0.0.3-cp39-cp39-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9Windows x86-64

CryptoSqlite-0.0.3-cp39-cp39-manylinux_2_28_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

CryptoSqlite-0.0.3-cp38-cp38-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.8Windows x86-64

CryptoSqlite-0.0.3-cp38-cp38-manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.28+ x86-64

CryptoSqlite-0.0.3-cp37-cp37m-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.7mWindows x86-64

CryptoSqlite-0.0.3-cp37-cp37m-manylinux_2_28_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.28+ x86-64

File details

Details for the file cryptosqlite-0.0.3.tar.gz.

File metadata

  • Download URL: cryptosqlite-0.0.3.tar.gz
  • Upload date:
  • Size: 38.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for cryptosqlite-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ccd7c8a2a3305d91a8c530e6ddc6e2ab8750a14a19bb822089c7315b987895c3
MD5 a5947de21a76be00b0ca6697c934d448
BLAKE2b-256 5d2b3cf51f933c36a97445144063f56f6bfd4313d36670d9acd47c8ba0fd68b7

See more details on using hashes here.

File details

Details for the file CryptoSqlite-0.0.3-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for CryptoSqlite-0.0.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a1c8d7ec994e67c2da946769063b2ab948cc2a26a5d95c91a7897441738a20b3
MD5 582004cb645174e3466d72726580c0a1
BLAKE2b-256 2c2f804a1566f78db3cb44d8b6d1247606cf76bbcf4fb2c4280fe2b25dd913f3

See more details on using hashes here.

File details

Details for the file CryptoSqlite-0.0.3-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for CryptoSqlite-0.0.3-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 24c0e30b379d52e4fdf4fdedc02351267fcc7ccf438e9cdc0e137c8f7da8d9a2
MD5 8151793f9cbdfbbd6878bbcb964e56ad
BLAKE2b-256 9a0a78a8c89f51086e839a39f32d6ced69960f6a6f684373b0e6cf2aa3dec038

See more details on using hashes here.

File details

Details for the file CryptoSqlite-0.0.3-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for CryptoSqlite-0.0.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a37242beb8e9885b5c4b05a6950fce271e94ea75fda0859fa333e14a5974ef0b
MD5 4a35a8faa55deb6e596df0a1e790836b
BLAKE2b-256 817dfec5c3c07b5e102d6345e332038c08207f2b08745ec2abf1ebb6f133ca49

See more details on using hashes here.

File details

Details for the file CryptoSqlite-0.0.3-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for CryptoSqlite-0.0.3-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ff60318c8efc1d607e84df4ffce14ab70b372958118149e3a9d5b0d09b7c6dc8
MD5 77f21ee6568b0ad895f0a60af6bbf5f8
BLAKE2b-256 5fe7aea73cb78a0d499a96cc51240baac7e50ba09012cd94e0e9a99e6c124d60

See more details on using hashes here.

File details

Details for the file CryptoSqlite-0.0.3-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for CryptoSqlite-0.0.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 cf41120a8f1af59184b5f8dd71b9ad3a48c550eefa819233fc969f8e6399253e
MD5 c1addde8166aea61b1e2b45fca2453ec
BLAKE2b-256 f64a17970d3c48e1a0a0a4e788776b1d938fccf75c846c391a6563a8dad56ea4

See more details on using hashes here.

File details

Details for the file CryptoSqlite-0.0.3-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for CryptoSqlite-0.0.3-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3c86865eff71506f18fe6e634293f7412ab64f89e263c9394a80eb1f4457ce11
MD5 8ef3123127d893a7561555bb30bdda72
BLAKE2b-256 0aa3f150844e3716fdc7f03ebb7b6866663e59f82161d57654b2e83a0ef89909

See more details on using hashes here.

File details

Details for the file CryptoSqlite-0.0.3-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: CryptoSqlite-0.0.3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for CryptoSqlite-0.0.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 872491b0648f93191bb523ecaaae604c742172cdd061095088e60772a4d18e98
MD5 8add59bf4b2e8535ff710a69aea5582b
BLAKE2b-256 00c1a51debd64101350c099decca28075e16a3b942816715d970359489c51578

See more details on using hashes here.

File details

Details for the file CryptoSqlite-0.0.3-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for CryptoSqlite-0.0.3-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d2bbffbd6f13911acc34b1573afd66b6dc2c8f0583c0bc50bf6f4c49bf2706e3
MD5 c7f6275a926781e788a2288336c4bcb9
BLAKE2b-256 336ecc49fa443d03515644c63f30d7c5c8191a6b781e48fc519400ba5e74dfce

See more details on using hashes here.

File details

Details for the file CryptoSqlite-0.0.3-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: CryptoSqlite-0.0.3-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for CryptoSqlite-0.0.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 6bf3afef4a68be3e4f61c7d6fcaba8e5e701b961e12a38a2d4fcaefee173e603
MD5 5b5fddf2ac3a84636055ceb02b7a2875
BLAKE2b-256 fbeb6de9c997bbb2369bf841c70a7306ea87a4049e3f99195a61a5ecded36e2b

See more details on using hashes here.

File details

Details for the file CryptoSqlite-0.0.3-cp38-cp38-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for CryptoSqlite-0.0.3-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 48ceaa438bcf1463c784af27491cb2052fdc878f80a0b061322493a030837d74
MD5 607bc35e6ba3ff0a16317ba160604768
BLAKE2b-256 ae4821302efb24604d1b283a457a66137422ead8831540364e1b2273c9cd8927

See more details on using hashes here.

File details

Details for the file CryptoSqlite-0.0.3-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for CryptoSqlite-0.0.3-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 fc997f516f64636caa172c2bf52b2fb7bbf817b4d838b66d04d92cf06e8345dd
MD5 b7932df2872a24702e47e6b95d02b1c9
BLAKE2b-256 fda748d41e9aef1a554e57d5c91e31c920901653e1b54a75da6b08149d80e067

See more details on using hashes here.

File details

Details for the file CryptoSqlite-0.0.3-cp37-cp37m-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for CryptoSqlite-0.0.3-cp37-cp37m-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 844352bbd17d92dc97a8a948e8d90113213cb133f549ab4e59f0966a80288c58
MD5 1fcbfbc08a43df8fd3f196549acb02d2
BLAKE2b-256 3ed25fa4465514ccec524d6cc12aa77db2bf5c0af1d10a39c2b098efc25d267c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page