8

我目前正在使用hibernate-sqlite

要访问动态创建的 sqlite 数据库,这非常有效。现在我想保护 sqlite 文件。经过一番研究,我发现要走的路是(AES)加密。任何人都可以向我解释这是否可以使用休眠?如果是这样,怎么办?如果这不起作用,是否有任何其他解决方案来保护文件中的数据?

4

2 回答 2

6

您可以使用 sqlite (System.Data.SQLite) 的内置加密。在http://sqlite.phxsoftware.com/forums/t/130.aspx查看更多详细信息

您还可以使用 SQLCipher,它是 SQLite 的开源扩展,提供透明的 256 位 AES 数据库文件加密。http://sqlcipher.net

因为你需要休眠

您可以使用 FluentNHibernate,您可以使用以下配置代码:

private ISessionFactory createSessionFactory()
{
    return Fluently.Configure()
            .Database(SQLiteConfiguration.Standard.UsingFileWithPassword(filename, password))
            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<DBManager>())
            .ExposeConfiguration(this.buildSchema)
            .BuildSessionFactory();    
}

private void buildSchema(Configuration config)
{
        if (filename_not_exists == true)
        {
            new SchemaExport(config).Create(false, true);
        }
}    

方法UsingFileWithPassword(filename, password)加密数据库文件并设置密码。它仅在创建新数据库文件时运行。用这种方法打开旧的未加密的失败。

编辑 :

为您提供更多选择

  • SEE - 官方实现。
  • wxSQLite - 一个 wxWidgets 风格的 C++ 包装器,它也实现了 SQLite 的加密。
  • SQLCipher - 使用 openSSL 的 libcrypto 来实现。
  • SQLiteCrypt - 自定义实现,修改 API。
  • botansqlite3 -botansqlite3 是 SQLite3 的加密编解码器,可以使用 Botan 中的任何算法进行加密.

SEE 和 SQLiteCrypt 需要购买许可证。

于 2012-12-21T07:02:07.633 回答
6

你知道SQLite 的加密扩展,对吧?

于 2012-12-20T21:11:14.710 回答