Page 1 of 1

Is this .db encrypted?

Posted: Tue 06 Oct 2015 13:35
by instrumentally
I have always been puzzled about LiteDAC with regards to this issue of encryption. I find it hard to believe that DevArt didn't build a simple procedure call to a table to query whether it is encrypted or not. To have to error trap one's source code in order to determine whether a table is encrypted or not seems odd. This is what I currently have to do to figure out whether a .db file is encrypted or not:

Code: Select all

  try
    LiteConnection.Open;
    FEncrypted:=true;
  except
    on E:Exception do
    begin
      msg:=E.Message;

      //try to open as unencrypted
      if (Pos('not a database', msg)>0) or (Pos('image is malformed', msg)>0) then
      begin
        liteConnection.EncryptionKey:='';
        try
          LiteConnection.Open;
          FEncrypted:=false;
        except
          on E:Exception do
            MessageDlg(E.ClassName + ': ' + E.Message, mtError, [mbOk], 0);
        end;
      end
      else
        MessageDlg(E.ClassName + ': ' + E.Message, mtError, [mbOk], 0);
    end;
  end;
The problem I've found with this is that exception message string has changed over time.

Is this the only way to determine if a .db is encrypted or not? To have to error trap and depend on a matching exception string?

Re: Is this .db encrypted?

Posted: Wed 07 Oct 2015 07:33
by AlexP
Hello,

Different error messages on an attempt to open an encrypted file were due to the fact that we encrypted file header in previous versions, and didn't in the latest versions. Instead of checking messages text, you can use the error codes:

Code: Select all

  SQLITE_NOTADB     = 26;   // File opened that is not a database file
  SQLITE_CORRUPT    = 11;   // The database disk image is malformed