8

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?

8
  • 1
    "Secure" is a rather vague term. Anybody who can read your database file probably also can read the key from your application. What exactly do you want to protect against? Commented Nov 13, 2012 at 14:37
  • For example the SQLite file is on a USB stick, but I only want a user knowing the encryption key to be able to read the file. Is there some sort of general encryption supported by SQLite reading applications? Commented Nov 15, 2012 at 9:29
  • Eg. In case of loss of the USB stick the file should be nothing to worry about (I understand encrypting the USB stick would be a solution but this is just an example any location should be secure) Commented Nov 15, 2012 at 9:30
  • So the user must enter the key every time your app is run? Or is the key stored in the app or on the computer? Commented Nov 15, 2012 at 10:21
  • 3
    Why are you trying to solve this at Hibernate level? Encrypt the USB stick using one of many available methods and deal with authentication when the drive is mounted. Commented Dec 20, 2012 at 20:50

2 Answers 2

6
+200

You know about SQLite's Encryption Extension, right?

Sign up to request clarification or add additional context in comments.

4 Comments

No I did not, weird I didn't find any information about it while researching encrypting sqlite
@theglauber if your are talking about SEE. its require a license means have to spend money for encryption
License fees aren't a problem, the URL in this answer finally explained how the encryption of an SQLite database is possible.
Cool; i was afraid i was stating something obvious; i'm glad it helped.
6

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.

1 Comment

FluentNHibernate is not available for Java. +1 for the list of options

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.