热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

python中的加密文件或数据库-Encryptedfileordbinpython

Ihaveasqlite3dbwhichiinsertselectfrominpython.Theappworksgreatbutiwanttotweakit

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 python? note i have no idea where to start.

我有一个sqlite3数据库,我在python中插入/选择。该应用程序工作得很好,但我想调整它,所以没有密码,没有人可以从数据库中读取。我怎么能在python中做到这一点?请注意我不知道从哪里开始。

5 个解决方案

#1


9  

You can use SQLCipher.

您可以使用SQLCipher。

http://sqlcipher.net/

Open Source Full Database Encryption for SQLite

SQLite的开源完整数据库加密

SQLCipher is an SQLite extension that provides transparent 256-bit AES encryption of database files. Pages are encrypted before being written to disk and are decrypted when read back. Due to the small footprint and great performance it’s ideal for protecting embedded application databases and is well suited for mobile development.

SQLCipher是一个SQLite扩展,为数据库文件提供透明的256位AES加密。页面在写入磁盘之前已加密,在读回时会被解密。由于占地面积小,性能卓越,因此非常适合保护嵌入式应用数据库,非常适合移动开发。

  1. Blazing fast performance with as little as 5-15% overhead for encryption on many operations
  2. 在许多操作中加密只需5-15%的开销即可实现快速性能

  3. 100% of data in the database file is encrypted Uses good security practices (CBC mode, key derivation)
  4. 数据库文件中100%的数据被加密使用良好的安全实践(CBC模式,密钥派生)

  5. Zero-configuration and application level cryptography Broad platform
  6. 零配置和应用级加密广泛平台

  7. support: works with C/C++, Obj-C, QT, Win32/.NET, Java, Python, Ruby, etc on Windows, Linux, iPhone/iOS…
  8. 支持:适用于Windows,Linux,iPhone / iOS上的C / C ++,Obj-C,QT,Win32 / .NET,Java,Python,Ruby等...

#2


2  

A list of Python encryption examples.

Python加密示例列表。

#3


2  

As Frontware suggests, you can use sqlcipher.

正如Frontware建议的那样,你可以使用sqlcipher。

pysqlcipher python package can make it easier to use since it uses the sqlcipher code amalgamation to compile the extension.

pysqlcipher python包可以使它更容易使用,因为它使用sqlcipher代码合并来编译扩展。

It should be just a matter of using pysqlcipher as you would use regular sqlite.dbapi2, just setting the right crypto pragmas.

它应该只是使用pysqlcipher,因为你会使用常规的sqlite.dbapi2,只需设置正确的加密pragma。

#4


1  

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

SQLite数据库非常易读,并且没有任何内置加密。

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. 使用文件系统权限而不是加密来保护数据库。你没有提到你的环境是什么,所以我不能说这是否适合你,但它可能是最简单和最可靠的方式,因为你无法尝试解密你无法阅读的内容。

  3. 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.
  4. 在写入之前在Python中加密,在阅读之后在Python中解密。相当简单,但是你失去了SQL基于集合的匹配操作的大部分功能。

  5. 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.
  6. 切换到另一个数据库;用户身份验证和权限是大多数多用户数据库的标准功能。当您发现自己不受工具的限制时,可能更容易查看其他工具而不是将新功能入侵当前工具。

#5


1  

I had the same problem. My application may have multiple instances running at the same time. Because of this, I can't just encrypt the sqlite db file and be done with it. I also don't believe that encrypting the data in python is a good idea, as you can't do any serious data manipulation in the database with it in this state.

我有同样的问题。我的应用程序可能同时运行多个实例。因此,我不能只加密sqlite db文件并完成它。我也不相信在python中加密数据是一个好主意,因为在这种状态下你不能在数据库中对它进行任何严格的数据操作。

With those constraints in mind, I have come up with the following two solutions:

考虑到这些限制因素,我提出了以下两个解决方案:

1) Use the before mentioned SQLCipher. The problems I see here, are that I will have to write my own bindings for Python, and compile it myself (or pay the fee). I might do this in either case as it would be a great solution for other Python developers out there. If I succeed, I will post back with the solution.

1)使用前面提到的SQLCipher。我在这里看到的问题是,我将不得不为Python编写自己的绑定,并自己编译(或支付费用)。在任何一种情况下我都可以这样做,因为对于其他Python开发人员来说这将是一个很好的解决方案。如果我成功了,我会回复解决方案。

2) If option 1 is too difficult for me, or too time consuming, I will use this method. This method is not as secure. I will use pycrypto to encrypt the database file. I will implement a SQL "server" which will decrypt the database file, then handle requests from various clients. Whenever there are no outstanding requests, it will reencrypt the database. This will be slower, over all, and leave the database in temporary decrypted states.

2)如果选项1对我来说太难,或者太耗费时间,我会使用这种方法。这种方法不够安全。我将使用pycrypto来加密数据库文件。我将实现一个SQL“服务器”,它将解密数据库文件,然后处理来自不同客户端的请求。每当没有未完成的请求时,它将重新加密数据库。总而言之,这将更慢,并使数据库处于临时解密状态。

Hope these ideas help the next guy.

希望这些想法可以帮助下一个人。

EDIT 1/13/2013

I gave up on SQLCipher because I couldn't seem to get it to compile, and the code base is trying to use OpenSSL, which while a sound library, is pretty massive of a code base for simple AES 128.

我放弃了SQLCipher,因为我似乎无法进行编译,而且代码库正在尝试使用OpenSSL,而OpenSSL虽然是一个声音库,却是简单的AES 128的代码库。

I found another option wxSQLite3, and I found out how to separate out just the SQLite encryption piece: https://github.com/shenghe/FreeSQLiteEncryption. I was able to get this to compile and work (with the latest version of SQLite3). wxSQLite3 also support AES 256 which is really cool. My next step is going to be to attempt to compile pysqlite (which is the sqlite library that comes built into python) with the modified sqlite3.dll. If that works, I'll tweak pysqlite to support the extended, encryption piece of the wxSQLite3's sqlite3.dll. In any case, I'll try to update this thread with my results, and if successful, I'll post the final code base, with build instructions, on Github.

我找到了另一个选项wxSQLite3,我发现了如何分离出SQLite加密文件:https://github.com/shenghe/FreeSQLiteEncryption。我能够编译和工作(使用最新版本的SQLite3)。 wxSQLite3也支持AES 256,这真的很酷。我的下一步是尝试使用修改过的sqlite3.dll编译pysqlite(这是python中内置的sqlite库)。如果可行,我将调整pysqlite以支持wxSQLite3的sqlite3.dll的扩展加密部分。在任何情况下,我都会尝试使用我的结果更新此线程,如果成功,我将在Github上发布带有构建指令的最终代码库。


推荐阅读
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • Java String与StringBuffer的区别及其应用场景
    本文主要介绍了Java中String和StringBuffer的区别,String是不可变的,而StringBuffer是可变的。StringBuffer在进行字符串处理时不生成新的对象,内存使用上要优于String类。因此,在需要频繁对字符串进行修改的情况下,使用StringBuffer更加适合。同时,文章还介绍了String和StringBuffer的应用场景。 ... [详细]
  • 本文详细介绍了Spring的JdbcTemplate的使用方法,包括执行存储过程、存储函数的call()方法,执行任何SQL语句的execute()方法,单个更新和批量更新的update()和batchUpdate()方法,以及单查和列表查询的query()和queryForXXX()方法。提供了经过测试的API供使用。 ... [详细]
  • 本文讨论了在数据库打开和关闭状态下,重新命名或移动数据文件和日志文件的情况。针对性能和维护原因,需要将数据库文件移动到不同的磁盘上或重新分配到新的磁盘上的情况,以及在操作系统级别移动或重命名数据文件但未在数据库层进行重命名导致报错的情况。通过三个方面进行讨论。 ... [详细]
  • Oracle seg,V$TEMPSEG_USAGE与Oracle排序的关系及使用方法
    本文介绍了Oracle seg,V$TEMPSEG_USAGE与Oracle排序之间的关系,V$TEMPSEG_USAGE是V_$SORT_USAGE的同义词,通过查询dba_objects和dba_synonyms视图可以了解到它们的详细信息。同时,还探讨了V$TEMPSEG_USAGE的使用方法。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • Oracle分析函数first_value()和last_value()的用法及原理
    本文介绍了Oracle分析函数first_value()和last_value()的用法和原理,以及在查询销售记录日期和部门中的应用。通过示例和解释,详细说明了first_value()和last_value()的功能和不同之处。同时,对于last_value()的结果出现不一样的情况进行了解释,并提供了理解last_value()默认统计范围的方法。该文对于使用Oracle分析函数的开发人员和数据库管理员具有参考价值。 ... [详细]
  • MyBatis错题分析解析及注意事项
    本文对MyBatis的错题进行了分析和解析,同时介绍了使用MyBatis时需要注意的一些事项,如resultMap的使用、SqlSession和SqlSessionFactory的获取方式、动态SQL中的else元素和when元素的使用、resource属性和url属性的配置方式、typeAliases的使用方法等。同时还指出了在属性名与查询字段名不一致时需要使用resultMap进行结果映射,而不能使用resultType。 ... [详细]
  • 本文详细介绍了在ASP.NET中获取插入记录的ID的几种方法,包括使用SCOPE_IDENTITY()和IDENT_CURRENT()函数,以及通过ExecuteReader方法执行SQL语句获取ID的步骤。同时,还提供了使用这些方法的示例代码和注意事项。对于需要获取表中最后一个插入操作所产生的ID或马上使用刚插入的新记录ID的开发者来说,本文提供了一些有用的技巧和建议。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 本文介绍了如何使用python从列表中删除所有的零,并将结果以列表形式输出,同时提供了示例格式。 ... [详细]
  • ALTERTABLE通过更改、添加、除去列和约束,或者通过启用或禁用约束和触发器来更改表的定义。语法ALTERTABLEtable{[ALTERCOLUMNcolu ... [详细]
  • 本文介绍了iOS数据库Sqlite的SQL语句分类和常见约束关键字。SQL语句分为DDL、DML和DQL三种类型,其中DDL语句用于定义、删除和修改数据表,关键字包括create、drop和alter。常见约束关键字包括if not exists、if exists、primary key、autoincrement、not null和default。此外,还介绍了常见的数据库数据类型,包括integer、text和real。 ... [详细]
author-avatar
齐cC含低
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有