Encrypted file or db in python

后端 未结 4 1814
借酒劲吻你
借酒劲吻你 2020-12-15 00:38

I have a sqlite3 db which i insert/select from in python. The app works great but i want to tweak it so no one can read from the DB without a password. How can i do this in

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-15 00:57

    SQLite databases are pretty human-readable, and there isn't any built-in encryption.

    Are you concerned about someone accessing and reading the database files directly, or accessing them through your program?

    I'm assuming the former, because the latter isn't really database related--it's your application's security you're asking about.

    A few options come to mind:

    1. Protect the db with filesystem permissions rather than encryption. You haven't mentioned what your environment is, so I can't say if this is workable for you or not, but it's probably the simplest and most reliable way, as you can't attempt to decrypt what you can't read.
    2. Encrypt in Python before writing, and decrypt in Python after reading. Fairly simple, but you lose most of the power of SQL's set-based matching operations.
    3. Switch to another database; user authentication and permissions are standard features of most multi-user databases. When you find yourself up against the limitations of a tool, it may be easier to look around at other tools rather than hacking new features into the current tool.

提交回复
热议问题