0

I have downloaded and installed TurboPack LockBox3 from GitHub into RAD Studio XE6. If I place the necessary components on a form then all works correctly. However, I need to be able to invoke my encryption routines at run time, so for test purposes have created a form with a couple of edit boxes and a button. The button event handler contains the following:


Codec1 := TCodec.Create(nil);
Codec1.CryptoLibrary := TCryptographicLibrary.Create(Codec1);
Codec1.StreamCipherId := uTPLb_Constants.BlockCipher_ProgId;
Codec1.cipher := 'native.AES-256';
Codec1.ChainMode := uTPLb_Constants.CBC_ProgId;
Codec1.Password := Password;
tmp := LBEdit1.Text;  // fetch the plaintext from form
if tmp <> '' then
begin
    Try
        Codec1.Reset;
        Codec1.EncryptString(tmp, ciphertext, TEncoding.UTF8);
        Edit1.Text := string(ciphertext);  // display the ciphertext
    Finally
        Codec1.Free;
    End;
end;

It compiles fine, but at run time I get an error message 'TSimpleCodec.Begin_EncryptMemory - Algorithms not set.' I am assuming I have not initialised something correctly but can't see what. Can anyone point me in the right direction please?

1 Answers1

1

I have it. The correct code should be:

    Codec1 := TCodec.Create(nil);
    CLib := TCryptographicLibrary.Create(nil);
    Codec1.CryptoLibrary := CLib;
    Codec1.StreamCipherId := uTPLb_Constants.BlockCipher_ProgId;
    Codec1.BlockCipherId := 'native.AES-256';
    Codec1.ChainModeID := uTPLb_Constants.CBC_ProgId;
    Codec1.AsymetricKeySizeInBits := 1024;
    Codec1.Password := Password;

I had initiallised Cipher, rather than BlockCipherID as above.