【问题标题】:Using SQLCipher in Python - the easy way [duplicate]在 Python 中使用 SQLCipher - 简单的方法 [重复]
【发布时间】:2019-11-20 23:03:03
【问题描述】:
我正在编写一个适用于加密 SQLite 数据库的 Python 实用程序。最终,我会将此类实用程序转换为可执行文件,以便更轻松地发送给我的团队的其他成员。
我阅读了很多关于 SQLCipher 的页面,但它们都在谈论在 Windows 中编译和安装 - 真的,我很难完全理解这一点,似乎他们采取了一些理所当然的步骤,我迷路了。
我在哪里可以找到详细的分步指南,让我拥有可以在加密的 SQLite 数据库上正常工作的 Python 代码,没有系统依赖项,然后可以将此类代码编译成 exe(使用 pyinstaller) ?即使有一个 exe 和一个 dll 也可以。
感谢您的帮助。
PS:我认为 exe + dll 是一个可行的选择,因为 DB Browser for SQLite (https://github.com/sqlitebrowser/sqlitebrowser) 附带了那个 dll。也许它可以重复使用?
【问题讨论】:
标签:
python
sqlite
encryption
sqlcipher
pysqlcipher
【解决方案1】:
我能够将 ssleay32.dll、libeay32.dll 和 sqlcipher.dll 复制到 Python38\DLLs 文件夹中。然后我将 sqlite3.dll 重命名为 sqlite3.dll.old。 sqlcipher.dll 需要重命名为 sqlite3.dll。然后像调用 sqlite 一样调用它。
适用于 Linux
sudo apt update
sudo apt upgrade
sudo apt install python3-pip python3-dev build-essential libssl-dev libffi-dev python3-setuptools
sudo apt-get install libsqlcipher-dev
sudo apt install build-essential git cmake libsqlite3-dev
sudo apt install sqlcipher
git clone https://github.com/rigglemania/pysqlcipher3
cd pysqlcipher3
python3 setup.py build
sudo python3 setup.py install
if installing in virtual environment also do
pip install pysqlcipher3 in the environment
if sys.platform.lower() == 'linux':
try:
from pysqlcipher3 import dbapi2 as sqlite3
except:
import sqlite3