SQLiteDatabase.EncryptionKey

From Xojo Documentation

Property (As String )
aSQLiteDatabase.EncryptionKey = newStringValue
or
StringValue = aSQLiteDatabase.EncryptionKey

Supported for all project types and targets.

Specifies the encryption key used to create or connect to an encrypted database.

Notes

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

To encrypt a new database, specify this value before calling CreateDataBaseFile.

To connect to an encrypted database, specify this value before calling Database.Connect.

To encrypt an existing database, use the Encrypt method.

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.

Sample Code

This code supplies EncryptionKey before attempting to connect to an encrypted database:

Dim dbFile As GetFolderItem("MyDB.sqlite")

Dim db As New SQLiteDatabase
db.DatabaseFile = dbFile

db.EncryptionKey = "horse+20$"

If db.Connect Then
// Key was correct; DB is connected
MsgBox("Connected to database.")
Else
// Connection error. This could be because the key is wrong or other reasons
MsgBox("Connection error: " + db.ErrorMessage)
End If