我目前使用的是hibernate-sqlite。
为了访问动态创建的sqlite数据库,这种方法工作得很好。现在我想保护sqlite文件。经过一些研究,我发现要去的方法是(AES)加密。谁能向我解释一下,使用hibernate是否可以做到这一点?如果是这样,又是如何做到的呢?如果这不起作用,有没有其他解决方案来保护文件中的数据?
发布于 2012-12-21 05:11:15
发布于 2012-12-21 15:02:08
您可以使用sqlite的内置加密(System.Data.SQLite)。欲了解更多详情,请访问http://sqlite.phxsoftware.com/forums/t/130.aspx
你也可以使用SQLCipher,它是SQLite的开源扩展,为数据库文件提供透明的256位加密。http://sqlcipher.net
当你需要hibernate时
您可以使用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和SQLiteCrypt需要购买许可证。
https://stackoverflow.com/questions/13361790
复制相似问题