v3.01 Direct mode & EncryptionAlgorithm Documentation? Demo Code?

v3.01 Direct mode & EncryptionAlgorithm Documentation? Demo Code?

Postby DespatchSystems » Thu 20 Sep 2012 13:23

Hi,

Maybe I am missing something, but I can't see anything new in the documentation or code demos that shows how to use "Direct Mode" or the new "EncryptionAlgorithm" in direct mode mentioned in the release notes:

3.0.1 10-Sep-12

- Rad Studio XE3 is supported
- Windows 8 is supported
- Data Explorer is supported
- dbExpress 4 metadata is supported
- A new driver for working in Direct mode is added
- The ForeignKeys and ForceCreateDatabase properties are added
- The EncryptionAlgorithm property is added for Direct mode driver
- The bug with setting the VendorLib property to a value different from "sqlite3.dll" is fixed

For such a major new feature, I was expecting an explanation in the documentation and at least some simple demo source code???

Hope you can help???

Greg
DespatchSystems
 
Posts: 14
Joined: Tue 24 Jul 2012 10:45

Re: v3.01 Direct mode & EncryptionAlgorithm Documentation? Demo Code?

Postby AlexP » Fri 21 Sep 2012 11:57

Hello,

Thank you for the information, we will add the description of the new features to the help in the next build of the driver. The following sample demonstrates working with an encrypted DB in the Direct mode, using the Blowfish algorithm. You can also use the following encryption algorithms: AES128, AES192, AES256, Blowfish, Cast128, RC4, TripleDES.

Code: Select all
try
    Database := ExtractFilePath(ParamStr(0)) + 'encrypted.db3';
    FConnection.Params.Values['DataBase'] := Database;

    // creating an encrypted database
    DeleteIfExists(Database);
    FConnection.Params.Values['ForceCreateDatabase'] := 'True';
    FConnection.Params.Values['EncryptionAlgorithm'] := 'Blowfish';
    FConnection.Params.Values['EncryptionKey']:= ' ';
    FConnection.Params.Values['NewEncryptionKey']:= 'bla-bla-bla';
    if not CheckConnectedResult(False, ExceptionMessage) then
      raise Exception.Create(ExceptionMessage + ' while creating a new database');
    FConnection.ExecuteDirect('CREATE TABLE TEST(ID INTEGER PRIMARY KEY)');
    FConnection.ExecuteDirect('INSERT INTO TEST VALUES(1);');
    FConnection.ExecuteDirect('INSERT INTO TEST VALUES(2);');
    FConnection.ExecuteDirect('INSERT INTO TEST VALUES(3);');
    FConnection.ExecuteDirect('INSERT INTO TEST VALUES(4);');
    FConnection.ExecuteDirect('INSERT INTO TEST VALUES(5);');

    // connect to the encrypted database with an incorrect key
    FConnection.Connected := False;
    FConnection.Params.Values['ForceCreateDatabase'] := 'False';
    FConnection.Params.Values['EncryptionKey']:= 'bla-bla';
    FConnection.Params.Values['NewEncryptionKey']:= '';
    ExceptionMessage := 'Invalid EncryptionKey and/or EncryptionAlgorithm specified';
    if not CheckConnectedResult(True, ExceptionMessage) then
      raise Exception.Create(ExceptionMessage + ' while connecting to the encrypted database with an invalid key');

    // connect to the encrypted database with the correct key
    FConnection.Connected := False;
    FConnection.Params.Values['ForceCreateDatabase'] := 'False';
    FConnection.Params.Values['EncryptionKey']:= 'bla-bla-bla';
    FConnection.Params.Values['NewEncryptionKey']:= '';
    if not CheckConnectedResult(False, ExceptionMessage) then
      raise Exception.Create(ExceptionMessage + ' while connecting to the encrypted database with the valid key');
    FConnection.ExecuteDirect('SELECT * FROM TEST');

    // decrypt the database
    FConnection.Connected := False;
    FConnection.Params.Values['EncryptionKey']:= 'bla-bla-bla';
    FConnection.Params.Values['NewEncryptionKey']:= ' ';
    if not CheckConnectedResult(False, ExceptionMessage) then
      raise Exception.Create(ExceptionMessage + ' while decrypting the database');

  finally
    FConnection.Connected := false;
    FConnection.Params.Values['DataBase'] := OldDataBase;
    FConnection.Params.Values['ForceCreateDatabase'] := 'False';
    FConnection.Params.Values['EncryptionKey']:= '';
    FConnection.Params.Values['NewEncryptionKey']:= '';
    FConnection.Params.Values['EncryptionAlgorithm'] := 'Default';
  end;
AlexP
Devart Team
 
Posts: 5528
Joined: Tue 10 Aug 2010 11:35


Return to dbExpress driver for SQLite