Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite encryption in java using Hibernate

I am currently using hibernate-sqlite.

To access dynamically created sqlite databases, this works perfectly. Now I want to secure the sqlite files. After some research I found out the way to go is (AES) encryption. Can anyone explain to me if this is possible using hibernate? And If so, how? If this doesn't work, is there any other solution for securing the data in the files?

like image 349
Thizzer Avatar asked Nov 13 '12 13:11

Thizzer


2 Answers

You know about SQLite's Encryption Extension, right?

like image 134
theglauber Avatar answered Oct 07 '22 20:10

theglauber


You can use the built-in encryption of the sqlite (System.Data.SQLite). See more details at http://sqlite.phxsoftware.com/forums/t/130.aspx

You can also Use SQLCipher, it's an opensource extension for SQLite that provides transparent 256-bit AES encryption of database files. http://sqlcipher.net

and as you need hibernate

you can use FluentNHibernate, you can use following configuration code:

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);
        }
}    

Method UsingFileWithPassword(filename, password) encrypts a database file and sets password. It runs only if the new database file is created. The old one not encrypted fails when is opened with this method.

EDIT :

more options for you

  • SEE - The official implementation.
  • wxSQLite - A wxWidgets style c++ wrapper that also implements SQLite's encryption.
  • SQLCipher - Uses openSSL's libcrypto to implement.
  • SQLiteCrypt - Custom implementation, modified API.
  • botansqlite3 - botansqlite3 is an encryption codec for SQLite3 that can use any algorithms in Botan for encryption.

The SEE and SQLiteCrypt require the purchase of a license.

like image 22
Jubin Patel Avatar answered Oct 07 '22 19:10

Jubin Patel