用 C# 加密 SQLite 数据库 [英] Encrypt SQLite database in C#

查看:22
本文介绍了用 C# 加密 SQLite 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 .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 Encryption ExtensionSQLite Crypt,但两者都是非免费的,而我的项目是在 GPL 下的.

There are tools like SQLite Encryption Extension and SQLite Crypt, but both are non-free, while my project is under GPL.

我想到的最简单的方法是让 SQLite 处理一个临时文件,然后在程序退出时对其进行加密,并覆盖(清零)原始文件.明显的缺点是如果程序崩溃(并且在它运行时),纯文本数据库是可访问的.

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] 也许我想多了.在连接字符串中使用密码选项就足够了吗?在这种情况下,文件是否会被正确加密(或者是某种较弱的保护)?

[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 实现.您可以从 https://system.data.sqlite.org 获取包装器,开发人员描述了如何在此论坛上使用加密:https://web.archive.org/web/20100207030625/http://sqlite.phxsoftware.com/forums/t/130.aspx.提示 - 您只需设置密码属性.他还在论坛的其他地方描述了他如何使用 Microsoft 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 https://system.data.sqlite.org, and the developer describes how to use the encryption on this forum at: https://web.archive.org/web/20100207030625/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 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆