delphiencryptiondelphi-xe4lockbox-3lockbox-2

Using LockBox3 with Delphi XE4 without installation


I'm porting program from Delphi 2009 to XE4 and got problem with LockBox encryption. Encrypt/decrypt unit is using just one component:

    interface

    function Encrypt(aStr: String): String;
    function Decrypt(aStr: String): String;
    function NeedEncrypt(): Boolean;

    implementation

    uses
    windows,
      strUtils,
      LbClass;

    var
      LbRijndael: TLbRijndael;
      localNeedEncrypt: Boolean;





    function NeedEncrypt(): Boolean;
    begin
      Result := localNeedEncrypt;
      localNeedEncrypt := False;
    end;

function Encrypt(aStr: AnsiString): AnsiString;
begin
  Result := aStr;
  if RightStr(aStr, 2) = '==' then
    Exit;
  Result := LbRijndael.EncryptString(aStr);
end;

function Decrypt(aStr: AnsiString): AnsiString;
begin
  Result := aStr;
  if RightStr(aStr, 2) = '==' then
    Result := LbRijndael.DecryptString(aStr)
  else
    localNeedEncrypt := True;
end;

    initialization
      LbRijndael := TLbRijndael.Create(nil);
      LbRijndael.GenerateKey('KEYABC');
      LbRijndael.CipherMode := cmECB;
      LbRijndael.KeySize := ks128;

    end.

As I understood there is no LockBox2 for Delphi XE4. Can I use LockBox3 for this purpose? If yes, can I use just needed units without installation into Delphi (this was done with LockBox2)?


Solution

  • Whilst the LB2 and LB3 APIs are very different, you should be able to port this code across without too much difficulty. As you are creating the components dynamically at runtime, you shouldn't need to install the packages into your IDE, providing your library path is set to include the LB3 source.