Pointer
Pointer

Reputation: 2186

How encrypt SQLite database with FireDAC?

I'm create SQLite databse with DB Browser for SQLite (non encrypted) and open with FireDAC in delphi.(Can retrive data Eg. Select * from abc).

How encrypt this SQLite database with FireDAC? When enter username, password and encrypt get message "Cipher DB is not encrypdet"

Note:

When create SQLite database from Delphi FireDac I can use encryption!

Upvotes: 1

Views: 2797

Answers (4)

Keri Fast
Keri Fast

Reputation: 1

I have faced several challenges when first time tried to encrypt SQLite database for use with Embarcadero FireDAC. Also all information is published by Embarcadero question pops up again and again on different forums. My case was solved based on community support, but when time has permitted simple Delphi application was assembled and available on Sourceforge. Hope it will make encryption/decryption slightly easier particularly for the newbie https://sourceforge.net/projects/sqlite-sequrity-for-delphi/

Upvotes: 0

Greg Dawson
Greg Dawson

Reputation: 180

To encrypt a database, use a TFDSQLiteSecurity Component. You'll also need a TFDSQLitePhysSQLiteDriverLink component to go along with it.

If a database is unencrypted, then its password is ''. So use '' as the OldPassword and create the new password in that case. Passwords are formatted as algorithm:PassPhrase. See documentation on the choices, I use aes-256. Also, the database needs to be closed when you do this.

...
//Change password
FDSQLiteSecurity1.Password := OldPassword;
FDSQLiteSecurity1.ToPassword := NewPassword;  // example: 'aes-256:mypassword123'
FDSQLiteSecurity1.ChangePassword;
...
//Remove Password
FDSQLiteSecurity1.Password := OldPassword;
FDSQLiteSecurity1.ToPassword := '';
FDSQLiteSecurity1.RemovePassword;
...

Upvotes: 3

MartynA
MartynA

Reputation: 30715

Recent Delphi versions come with an example project for working with encryption on Sqlite databases, see this documentation. I have not used this myself, btw.

It includes this section

Encrypt DB
    Encrypt: Encrypts the database according to the Encryption mode and the password provided.

The sampe uses TFDSQLiteSecurity.SetPassword to encrypt the database with the password provided.

The database password is the combination of <encryption algorythm>:<password>. 

Upvotes: 1

Nasreddine Galfout
Nasreddine Galfout

Reputation: 2591

From the Documentation

SQLite Encrypted Database

Approach

One of the distinctive SQLite features is the high-speed strong database encryption. It allows you to make database file content confidential and enforce integrity control on the database file. The encrypted database format is not compatible with other similar SQLite encryption extensions. This means that you cannot use an encrypted database, encrypted with non-FireDAC libraries. If you need to do this, then you have to decrypt a database with an original tool and encrypt it with FireDAC.

Upvotes: 1

Related Questions