Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
CodeDatabaseDelphiRAD Studio

Quickly Encrypt / Decrypt An SQLite Database With The FireDAC.SQLite Encryption Sample For Delphi

The SQLite Encryption sample is an encryption/decryption demo.

Location

You can find the SQLite Encryption sample project at:

  • Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to – Object Pascal\Database\FireDAC\Samples\DBMS Specific\SQLite\Encryption
  • Subversion Repository – you can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

Description

This sample allows the user to perform the following operations:

  • Encrypting the DB using different encryption modes and passwords.
  • Changing the DB password of the encrypted database.
  • Getting the state of the DB.
  • Decrypting the DB.

How to Use the Sample

  1. Navigate to the location given above and open SQLite_Encrypt.dproj.
  2. Press F9 or choose Run > Run.
  3. Click Create in the Create new DB tab to:
    1. Create an empty and unencrypted database located at: C:\Users\test\AppData\Local\Temp\test.sdb.
    2. Create an empty table into the new database.
    3. Populate the table.
  4. Once the table is added to the database, you can start interacting with the sample.

Files

File in DelphiContains
SQLite_Encrypt.dproj
SQLite_Encrypt.dpr
The project itself.
fMain.pas
fMain.fmx
The main form.

Implementation

The sample implements the following features.

Create new DB

  • Create: Creates the database, a table into the database, and populates the table using TFDScript component.
  • Drop: Removes the database if exists.

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>.

Change DB pwd

Use this tab to change the password of the encrypted database.

The sample uses TFDSQLiteSecurity.ChangePassword to change the password of the encrypted database from Password to ToPassword.

To change the password:

  1. Write the new password in the field.
  2. Click Change to update the password.

Get state

  • Get: Returns the database encryption status.

The sample uses TFDSQLiteSecurity.CheckEncryption to request the database encryption status.

Possible status:

  • <unencrypted>: The database is unencrypted.
  • <encrypted>: The database is encrypted, but the algorythm / password is wrong.
  • Encryption algorythm name, and the data from the database: The database is encrypted, and the algorythm / password are correct.

Decrypt DB

  • Decrypt: Removes the password and decrypts the database.

The sample uses TFDSQLiteSecurity.RemovePassword to remove the password and decrypt the database.

For the original post of Embarcadero, please folow the link below:

http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.SQLite_Encryption_Sample


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Related posts
DelphiRAD Studio

How To Create A Cross-Platform News App With Delphi

Developer InterviewsInterviewNews

What Is It Like To Be A Developer Dr. Holger Flick?

DelphiNewsRAD Studio

Welcome to the future of software development, again

DelphiRAD Studio

How To Capture Highly Customizable Website Snapshots

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES