user34537
user34537

Reputation:

encrypt a file automagically in C#?

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.

Upvotes: 1

Views: 1336

Answers (3)

ChrisPelatari
ChrisPelatari

Reputation: 689

SQLiteConnection.SetPassword

SQLite ADO.NET provider

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

Upvotes: 0

Jeroen Landheer
Jeroen Landheer

Reputation: 9905

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.

Upvotes: 7

overslacked
overslacked

Reputation: 4137

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.

Upvotes: 2

Related Questions