tags:

views:

409

answers:

3

How do i encrypt a file in C#? i would like to use a db (like sqlite) and use it normally except have the file encrypted and have my user enter his password before having access to the database.

+2  A: 

SQL Server Compact Edition (it's an inprocess database server like SQLite) allows you to encrypt the file without writing any additional code.

To change the password, use the Engine.Compact method.

overslacked
+7  A: 

There are multiple ways to do this:

  • Use DPApi (Data Protection API), which is supplied in the ProtectedData (System.Security.Cryptography class), and use an entrophy based on a password
  • Use SQL Compact Edition, which has this built in
  • Generate a key based on a password and encrypt/decrypt the file with that
  • Use Encrypted File System, so the OS will take care of encryption on the disk. (Consumer editions of Windows don't have this though.)

And there are probably more ways to do this.

Hope this helps.

Jeroen Landheer
If you use EFS remember to back up the keys!
RobS
As with any security application, encrypted data without a key is like a locked door without a key. You may be able to get in, but it is going to take a lot of time :)
Jeroen Landheer
A: 

SQLiteConnection.SetPassword

SQLite ADO.NET provider

I think you also have to set the Password= parameter in the connection string.

blue_fenix