问题描述
什么是在.net / C#加密SQLite数据库文件,最好的方法?我使用的sqlite-dotnet2 的包装。
What is the best approach to encrypting a SQLite database file in .Net/C#? I'm using sqlite-dotnet2 wrapper.
有像 SQLite的加密扩展和的,但都是非自由的,而我的项目是根据GPL。
There are tools like SQLite Encryption Extension and SQLite Crypt, but both are non-free, while my project is under GPL.
在幼稚的做法我想用的是让SQLite的处理临时文件,然后把它在程序退出加密,并覆盖(零出)原件。最明显的缺点是,如果程序崩溃(尽管它正在运行),纯文本DB访问。
The naive approach I thought of using was to let SQLite handle a temporary file, then to encrypt it on program exit, and overwrite (zero-out) the original. The obvious drawback is that if program crashes (and while it is running), the plain text DB is accessible.
有没有更好的方式来处理这个?我可以通过一个加密流到包装材料(而不是使用SQLiteConnection.CreateFile)?
Is there a better way to approach this? Can I pass an encrypted stream to the wrapper (instead of using SQLiteConnection.CreateFile) ?
也许我该得太多。是足以在连接字符串中使用密码的选项?请问该文件在这种情况下适当进行加密(或者是一些实力较弱的保护)?
[edit] Maybe I am overthinking this. Is is sufficient to use Password option in the connection string? Would the file be encrypted properly in that case (or is it some weaker protection)?
推荐答案
我建议使用System.Data.Sqlite包装,其中包括加密。它的伟大工程,它很容易使用,它是一个完整的ADO.Net实现。你可以从 http://sqlite.phxsoftware.com/ 包装,开发人员介绍了如何使用加密对他的论坛在:http://sqlite.phxsoftware.com/forums/t/130.aspx.提示 - 你刚才设置的密码属性。他还描述了他是如何做的论坛使用微软的Crypto API的其他地方进行加密。
I recommend using the System.Data.Sqlite wrapper, which includes encryption. It works great, it's easy to use, and it's a complete ADO.Net implementation. You can get the wrapper from http://sqlite.phxsoftware.com/, and the developer describes how to use the encryption on his forum at: http://sqlite.phxsoftware.com/forums/t/130.aspx. Hint - you just set the password property. He also describes how he does the encryption using the Microsoft Crypto API elsewhere in the forum.
这篇关于在C#中加密的SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!