Encrypt a database
The following example shows how to encrypt an existing database:
UniConnection.Database := 'C:\sqlite.db3';
UniConnection.SpecificOptions.Values['ForceCreateDatabase'] := 'False';
UniConnection.SpecificOptions.Values['Direct'] := 'True';
UniConnection.SpecificOptions.Values['EncryptionAlgorithm'] := 'leBlowfish';
UniConnection.SpecificOptions.Values['EncryptionKey'] := '';
UniConnection.Open;
TLiteUtils.EncryptDatabase(UniConnection, '11111');
Creating of a new encrypted database
The following example shows creating a new encrypted database:
UniConnection.Database : = 'C:\sqlite_encoded.db3';
UniConnection.SpecificOptions.Values['ForceCreateDatabase'] := 'True';
UniConnection.SpecificOptions.Values['Direct'] := 'True';
UniConnection.SpecificOptions.Values['EncryptionAlgorithm'] := 'leBlowfish';
UniConnection.SpecificOptions.Values['EncryptionKey'] := '11111';
UniConnection.Open;
Connecting to an encrypted database
To connect to an existing encrypted database, the following should be performed:
UniConnection.Database := 'C:\sqlite_encoded.db3';
UniConnection.SpecificOptions.Values['ForceCreateDatabase'] := 'False';
UniConnection.SpecificOptions.Values['Direct'] := 'True';
UniConnection.SpecificOptions.Values['EncryptionAlgorithm'] := 'leBlowfish';
UniConnection.SpecificOptions.Values['EncryptionKey'] := '11111';
UniConnection.Open;
Changing the encryption key for the database
To change the encryption key in the encrypted database, you must perform the following:
UniConnection.Database := 'C:\sqlite_encoded.db3';
UniConnection.SpecificOptions.Values['ForceCreateDatabase'] := 'False';
UniConnection.SpecificOptions.Values['Direct'] := 'True';
UniConnection.SpecificOptions.Values['EncryptionAlgorithm'] := 'leBlowfish';
UniConnection.SpecificOptions.Values['EncryptionKey'] := '11111';
UniConnection.Open;
TLiteUtils.EncryptDatabase(UniConnection, '22222');
After changing the encryption key, the database connection remains open and the further work with the database can continue. However, if disconnected from the database and for subsequent connection, the new value of the encryption key should be assigned to the UniConnection.EncryptionKey property.