SQLiteDatabase.Encrypt

From Xojo Documentation

Method

SQLiteDatabase.Encrypt(password As String)

Supported for all project types and targets.

Encrypts the database using password as the encryption key. If you are already connected to an encrypted database and call Encrypt with an empty string, the database is decrypted.

Notes

fa-info-circle-32.png
You cannot encrypt a database from within a transaction. You must encrypt it outside of any transactions.

Encrypt can be used both to encrypt a non-encrypted database, to change the password for an existing encrypted database and to decrypt a database.

Encrypt does not yield to threads, so it will freeze the application for large databases.

Always back up the database before encrypting it.

2017r3 and prior: AES-128 encryption is always used.

2018r1 and later defaults to AES-128, but AES-256 can also be used by including the prefix "aes256:" before the rest of the encryption key.

If you have a database that was previously encrypted as AES-128 and would like to switch to AES-256, first remove the encryption using Decrypt and then encrypt it again with Encrypt.

Sample Code

This example encrypts a database using the passed password.

Var db As New SQLiteDatabase
db.DatabaseFile = New FolderItem("db.sqlite")
Try
db.Connect
db.Encrypt("howdy+doody")
Catch error As DatabaseException
// handle error here
End Try

See Also

EncryptionKey, Decrypt