SQLite3 database encryption — determining encryption library?

妖精的绣舞 提交于 2019-12-10 19:13:12

问题


I am considering supporting encrypted sqlite databases for a PHP application. I am using SQLite3 extension of PHP and it seems, that they already support an encryption method, at least SQLite3::__construct allows for an encryption-key to pass.

What i was not able to figure out is, which encryption library they are talking about in the documentation. By googling i found the following:

  • sqlcipher
  • sqlite see
  • sqlite crypt

What is not clear to me is:

  • how these libraries integrate with SQLite3
  • if they share compatibility to each other regarding to specifying the encryption key and setting up data access etc.
  • if i can automatically detect in my application if any and which encryption library my SQLite3 installation is supporting, so it would be possible for my application to support different encryption libraries

Any help is very much appreciated!


回答1:


The SQLite3 library needs to be built with support for encryption. Those projects (and a few more: https://stackoverflow.com/a/5877130/502789) can be used to get an sqlite3.so/dll with encryption support.

So, the questions...

  1. They don't integrate with sqlite. They offer a replacement sqlite3 library with encryption support
  2. Vanilla SQLite3 provides the API required for encryption, but it's unimplemented. I believe SQLiteCrypt uses its own API and so won't work here (don't quote me on that).
  3. Your SQLite3 installation doesn't support it, you need to replace it with an SQLite3 library compiled with this feature (see the options I linked).

NB: I haven't used PHP + SQlite3 encryption.




回答2:


As far as I'm aware, the password you pass to the PHP open will only work if you are using a version of SQLite compiled with encryption support (i.e. the encryption doesn't work in a default build).

We've had some users successfully use SQLCipher with PHP by building the PHP software with the SQLCipher codebase. More information is available in the thread here:

http://groups.google.com/group/sqlcipher/browse_thread/thread/6d77e4ef2a1530d7




回答3:


One post that seemed useful for SQLite encryption was posted by and admin explaining how to use sqlcipher http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/14965-android-database-encryption-sqlcipher-library.html




回答4:


Please see my answer here: https://stackoverflow.com/a/49161716/9418360

SQLite3 has built-in interface for encryption. You need to enable it in config.m4 : -DSQLITE_HAS_CODEC=1 I have developed my own encryption based on AES. A few C files in /ext/sqlite3/libsqlite and it works great. The whole database file is encrypted, no need to send encrypted data from PHP. As soon as I have my code ready to publish will update this post. Cheers.



来源:https://stackoverflow.com/questions/9514007/sqlite3-database-encryption-determining-encryption-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!