delphifiremonkeydelphi-xe7lockbox-3

Lockbox 3 for Android with XE7 not working


I just found that lockbox 3.6.0 should support Android. However when i look in my palette i see that the codec only supports win32 and win64.

How can i make it work for my android apps also?

Im using Delphi XE7 and have already followed the installation instructions supplied in the package. For a windows app it works just fine.


Solution

  • You have two options:

    (1) Run-time

    You can always create the components at run-time. There is an example on the website on how to do it, and I copy a fragment of this example below. Just replace the ShowMessage() functions with whatever is appropriate ...

    procedure EncryptAStream( Plaintext, Ciphertext: TStream);
    var
     Codec1: TCodec;
     CryptographicLibrary1: TCryptographicLibrary;
    begin
    ShowMessage( 'Demonstration of How to Encrypt a Stream with TurboPower LockBox 3.');
    Codec1 := TCodec.Create( nil);
    CryptographicLibrary1 := TCryptographicLibrary.Create( nil);
    Codec1.CryptoLibrary  := CryptographicLibrary1;
    Codec1.StreamCipherId := uTPLb_Constants.BlockCipher_ProgId;
    Codec1.BlockCipherId  := 'native.AES-256';
    Codec1.ChainModeId    := uTPLb_Constants.CBC_ProgId;
    Codec1.Password := 'my utf-16le password';
    
    // Codec1.Reset;  Reset if you are continuing from a previous encryption operation.
    Codec1.EncryptStream( Plaintext, Ciphertext);
    // Codec1.Burn;   Burn if you need to purge memory of sensitive data.
    
    Ciphertext.Position := 0;
    
    ShowMessageFmt(
     'The ciphertext for AES-256 with CBC chaining'#13#10 +
     ' of plaintext ''banana'' (UTF-8 encoding),'#13#10 +
     ' and password ''my utf-16le password'' (UTF-16LE encoding),'#13#10 +
     ' prepended by 64 bit nonce, (being the IV),'#13#10 +
     ' and rendered for display in base64 is ...'#13#10 +
     '%s', [Stream_to_Base64( Ciphertext)]);
    
    Codec1.Free;
    CryptographicLibrary1.Free;
    end;
    

    (2) Design-time

    A little bit of tweaking is required to get the components onto the palette for Android. This will be done for you in the next version of TPLockbox 3 to be released, but for now, here is the procedure ...

    1. Remove vcl, vclimg and dbrtl from the TPLB3 run-time requirements.
    2. For the run-time package, add the Android target platform, and make it the active one. But of course, don't add this platform to the design-time package.
    3. The binary product for the run-time should be named libTP_LockBox3_XE7.so, where XE7 is a place-marker for your compiler version.
    4. Preface the declarations for the two components (TCodec and TCryptographicLibrary) with

      [ComponentPlatformsAttribute( pidWin32 or pidWin64 or pidOSX32 or pidiOSSimulator or pidiOSDevice or pidAndroid)]
      TCodec = class( TTPLb_BaseNonVisualComponent, ICryptographicLibraryWatcher,
                       { etc. }
      

    This is the key to the whole thing. The ComponentPlatformsAttribute attribute declares what platforms should the component be displayed for, on the palette. If not declared, I believe that the default is pidWin32 or pidWin64, but I cannot point to any official documentation to support this.

    1. Recompile the run-time package. Remember that if your are compiling with MS-BUILD, on certain compiler versions, you need to save-all before you can successfully compile.
    2. Go to the IDE Tools | Options and open the Library Path for the Android platform. Make sure that this path include the location of where you put the dcu files for the Android case. For example, on my installation it is ...

      C:\Dev\TPLB\work-products\ephemeral\dcu\XE6\Android

    You should physically check this directory. It should have a file named TPLB3.AES.dcu and another named TPLB3.AES.so for example.

    1. Recompile and re-install the design-time package
    2. Open your mobile project. Slap design-time components for TCodec and TCryptographicLibrary on your Android forms. Proceed as you would for a windows application.