dotConnect for SQLite Professional edition provides built-in encryption capabilities for SQLite databases. This feature allows you to:
The SQLite database engine provides the ability to work with encrypted databases. Encryption and decryption operations are performed transparently during read/write operations on the database file. These operations are completely transparent to applications accessing the database.
dotConnect for SQLite supports the following encryption algorithms:
To encrypt an unencrypted database, use the following PRAGMA statements:
PRAGMA ENCRYPTION = algorithm;
PRAGMA REKEY = 'encryption_key';
Where algorithm
is one of the supported encryption algorithms listed above, and encryption_key
is your chosen encryption key.
For example:
PRAGMA ENCRYPTION = AES256;
PRAGMA REKEY = 'mySecretKey123';
To connect to an encrypted database, you need to specify the encryption algorithm and key in the connection string:
string connectionString = "Data Source=MyDatabase.db;EncryptionAlgorithm=AES256;EncryptionKey=mySecretKey123;";
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{
connection.Open();
// Perform database operations
}
To change the encryption key of an encrypted database, use the PRAGMA REKEY statement:
PRAGMA REKEY = 'newEncryptionKey';
Alternatively, you can use the ChangePassword
method of the SQLiteConnection
class:
connection.ChangePassword("newEncryptionKey");
Note that the ChangePassword
method only works with SEE or SQLiteCrypt encrypted databases and accepts the new password in UTF-8 encoding.
To decrypt an encrypted database, set an empty value for the PRAGMA REKEY statement:
PRAGMA REKEY = '';
dotConnect for SQLite fully supports connecting to SQLCipher encrypted databases. However, it does not provide the SQLCipher extension itself. To use SQLCipher encryption, you need to purchase SQLCipher separately.
To connect to a SQLCipher encrypted database:
Encryption
connection string parameter to SQLCipher
.Password
and EncryptionLicenseKey
connection string parameters.Example:
string connectionString = "Data Source=MyDatabase.db;Encryption=SQLCipher;Password=myPassword;EncryptionLicenseKey=YourLicenseKey;";
To create an encrypted copy of an unencrypted database using SQLCipher, use the SQLCipherExport
method:
connection.SQLCipherExport("EncryptedDatabase.db", "password");
dotConnect for SQLite also supports SQLiteCrypt encryption. Like SQLCipher, you need to purchase SQLiteCrypt separately.
To connect to a SQLiteCrypt encrypted database:
Encryption
connection string parameter to SQLiteCrypt
.Password
and EncryptionLicenseKey
connection string parameters.Example:
string connectionString = "Data Source=MyDatabase.db;Encryption=SQLiteCrypt;Password=myPassword;EncryptionLicenseKey=YourLicenseKey;";
The implementation of database encryption in dotConnect for SQLite is compatible only with other Devart products, such as LiteDAC and UniDAC. dotConnect for SQLite can only work with databases that were encrypted by itself, LiteDAC, or UniDAC.
Built-in encryption in dotConnect for SQLite Professional provides a secure way to protect your SQLite databases. By using this feature, you can ensure that sensitive data stored in your databases remains confidential and protected from unauthorized access. Whether you choose to use the built-in encryption algorithms or third-party solutions like SQLCipher or SQLiteCrypt, dotConnect for SQLite offers flexible options for database encryption.