Page 1 of 1

SQLite Android encryption

Posted: Sun 26 Oct 2014 15:15
by Zvor
Hello!
I have noticed the ability of using Direct mode on Android platform appeared in the most recent update of liteDAC! Does that mean encription is working too?
If not how is it possible to use third-party driver with liteDAC to get encription on Android using RAD Studio XE7?
Thanks

Re: SQLite Android encryption

Posted: Mon 27 Oct 2014 06:05
by AlexP
Hello,

Encryption is implemented by us in the Direct mode supported for Windows platforms only. For other platforms, you should use an external SQLite3 library with support for encryption. You can specify the SQLite3.dll location in the LiteConnection.ClientLibrary property.

Re: SQLite Android encryption

Posted: Mon 27 Oct 2014 07:41
by Zvor
OK, many thanks, but how can i use alternative drivers on Android?
Should i use .dll or .so file?

Re: SQLite Android encryption

Posted: Mon 27 Oct 2014 09:27
by AlexP
For Android, libraries usually have the extension .so

Re: SQLite Android encryption

Posted: Mon 27 Oct 2014 11:14
by Zvor
Can you show me some example how to connect to sqlite database using alternative library on Android?
I think about using SQLCipher open source but i don't see any .so files in it's distribution.
Maybe you can show with another library?

Thanks a lot

Re: SQLite Android encryption

Posted: Tue 28 Oct 2014 10:24
by AlexP
To work with third-party libraries, you should specify the path to the library in the LiteConnection.ClientLibrary property. We don't use and test our products on third-party libraries. You have to search for such libraries and test their functioning with LiteDAC.

Re: SQLite Android encryption

Posted: Wed 29 Oct 2014 17:20
by Zvor
OK, thanks for your answer, one last question -
is it possible to use data encryption instead of database encryption on Android platform?

Re: SQLite Android encryption

Posted: Thu 30 Oct 2014 09:11
by AlexP
Yes, you may use data encryption in mobile applications. More details about data encryption can be found in the documentation: http://www.devart.com/litedac/docs/encryption.htm

Re: SQLite Android encryption

Posted: Thu 30 Oct 2014 10:28
by Zvor
Thank you for your answer, but i don't quite understand how to use it.

I have SQlite database file with tables Log, Backup, text.

Code: Select all

CREATE TABLE [text] ([test] BINARY);
I plased components UniConnection, UniQuery and Encryptor with options:

Code: Select all

object SQLLocal: TUniConnection
    ProviderName = 'SQLite'
    SpecificOptions.Strings = (
      'SQLite.UseUnicode=True'
      'SQLite.EnableLoadExtension=True')
    Options.KeepDesignConnected = False
    LoginPrompt = False
end;

  object LocalDataSet: TUniQuery
    LocalUpdate = True
    Encryption.Fields = 'test'
    Encryption.Encryptor = UniEncryptor
    Connection = SQLLocal
    Options.FieldsOrigin = True
  end

  object UniEncryptor: TUniEncryptor
    Password = '1'
  end
Now on ButtonPress i do

Code: Select all

 localdataset.SQL.text:='INSERT INTO Text (test) VALUES (''123123 qwerty йцукен'')';
 UniEncryptor.Password := '1';
 localdataset.ExecSQL;

 localdataset.SQL.text:='SELECT * FROM text';
 localdataset.DataTypeMap.AddFieldNameRule ('test', ftwidestring);
 localdataset.Open;
and got error "Field: test String value is too long: <lots of hieroglyphs>".
If I don't use DataTypeMap no error occured but still i can open database with external database administration tool and see that my data looks like ''123123 qwerty йцукен''.

What am i doing wrong? Can Encryptor handle with cirillic symbols?

Re: SQLite Android encryption

Posted: Fri 31 Oct 2014 06:26
by AlexP
There is a sample of a console application demonstrating work with UniEncryption:

Code: Select all

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Uni,
  CREncryption,
  SQLiteUniProvider,
  windows;

var
  UniConnection: TUniConnection;
  UniQuery: TUniQuery;
  UniEncryption: TUniEncryptor;
begin
  UniConnection := TUniConnection.Create(nil);
  try
    UniConnection.ConnectString := 'ProviderName=SQLite;Data Source=:memory:;UseUnicode=true;LoginPrompt=False';
    UniConnection.Connect;
    UniConnection.ExecSQL('CREATE TABLE [test] ([txt] varchar2(2000))');
    UniEncryption := TUniEncryptor.Create(nil);
    UniEncryption.Password := '12345';
    try
      UniQuery := TUniQuery.Create(nil);
      try
        UniQuery.Connection := UniConnection;
        UniQuery.Encryption.Encryptor := UniEncryption;
        UniQuery.Encryption.Fields := 'txt';
        UniQuery.SQL.Text := 'select * from test';
        UniQuery.Open;
        UniQuery.Insert;
        UniQuery.Fields[0].AsString := 'test äöü эъя';
        UniQuery.Post;
        MessageBox(0, PChar(UniQuery.Fields[0].AsString), 'test', 0);
        UniQuery.Close;
        UniQuery.Encryption.Encryptor := nil;
        UniQuery.Open;
        MessageBox(0, PChar(UniQuery.Fields[0].AsString), 'test', 0);
        UniQuery.Close;
      finally
        UniQuery.Free;
      end;
    finally
      UniEncryption.Free;
    end;
  finally
    UniConnection.Free;
    readln;
  end;
end.