使用Hibernate在java中加密SQLite

Thy*_*hys 9 java sqlite encryption hibernate

我目前正在使用hibernate-sqlite.

要访问动态创建的sqlite数据库,这非常有效.现在我想保护sqlite文件.经过一些研究,我发现了可行的方法是(AES)加密.任何人都可以解释一下,如果使用hibernate这是可能的吗?如果是这样,怎么样?如果这不起作用,是否还有其他解决方案来保护文件中的数据?

the*_*ber 6

您了解SQLite的加密扩展,对吗?


Jub*_*tel 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);
        }
}    
Run Code Online (Sandbox Code Playgroud)

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

编辑:

更多选择

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

SEE和SQLiteCrypt需要购买许可证.