How to encrypt an existing sqlite db

Could some one explain to encrypt an SQLite database which is already existing with data. or if possible to password protect.

You can encrypt/decrypt an sqlitedatabase at any time. Just call the Encrypt method.

From documentation:

Dim db As New SQLiteDatabase db.DatabaseFile = GetFolderItem("db.sqlite") If db.Connect Then db.Encrypt("howdy+doody") Else //handle error here End If

There is no database inherent way to set a password. SQLite does not know any useridentification (Unlike CubeSQL). But you can set/un-set encryption for a SQLite Database file by using the methods of Xojo’s SQLiteDatabase class. Then you can use the encryption key just like a password (and ask your users for it).

What happens when an SQLite encrypted database is decrypted for reading and the application crash. Will the database will still be encrypted or will it be corrupted.

After you have called Encrypt to encrypt the database, you do not need to call Decrypt ever, unless you want to completely remove the encryption. Instead, you supply the encryption key before you connect. The database remains encrypted, but you can still read and write it.

Provide the encryption key BEFORE you connect to the database file. From then on you do not need to call decrypt, you can access read/write/update/delete as usual. Call decrypt only if you actually want to have a decrypted file which can be accessed by others or with other tools.

See “Encrypted Databases” in the notes section:

// When you open an encrypted database file, you need to supply the key: Dim db As New SQLiteDatabase db.DatabaseFile = GetFolderItem("db.sqlite") db.EncryptionKey = "howdy+doody" If Not db.Connect Then //handle error here End If

Thanks Oliver for the info.