2

I'd like to migrate my old crypto functions from lockbox2 to lockbox3 on delphi XE6. Before to do that I've made a code (CipherComp.dpr) to compare the output, since the setup have changed.

I'm using AES-ECB (to avoid IV) 256 bits, key: '1234567890', text: 'a secret word'

Using TPLB2 I initialize like

  FAES : TLbRijndael;

  FAES := TLbRijndael.Create(nil);
  FAES.CipherMode := cmECB;   // cmECB (default), cmCBC
  FAES.KeySize := ks256;      // ks128, ks192
  FAES.SetKey('1234567890');  // set the password here

and encrypt using:

  Result := FAES.EncryptString(pString);

on the other hand on TPLB3 changes like this

  FCodec: TCodec;
  FCryptoLib: TCryptographicLibrary;

  FCodec := TCodec.Create(nil);
  FCryptoLib := TCryptographicLibrary.Create(nil);

  FCodec.CryptoLibrary := FCryptoLib;
  FCodec.StreamCipherId := uTPLb_Constants.BlockCipher_ProgId;
  FCodec.BlockCipherId  := 'native.AES-256';
  FCodec.ChainModeId    := uTPLb_Constants.ECB_ProgId;
  FCodec.Password := '1234567890';

and encrypt

  FCodec.EncryptAnsiString(pString, Result);

but the output mismatch when cipher the same text.

a secret word qD9+fF1EqdQH8C3TrEaLQg==
a secret word 1bUXLgXwob1cL6O27HMViw==

I'm doing something wrong but I can figure out what.

Any hint?

Thanks in advance.

Gonzalo A.
  • 123
  • 7
  • Encryption operates on binary data. You are supplying text. How are you expecting the library to encode the text? – David Heffernan Nov 05 '15 at 18:19
  • @David, the functions deal with plaintext. If something missing when I encrypt a text, the operation Decrypt(Encrypt(X))=X should fail, but it doesn't. – Gonzalo A. Nov 06 '15 at 09:42
  • That's a false conclusion. If the crypt/decrypt use the same encoding then that will be true. The point is that you need that encoding to match between the two variants, not just between the crypt/decrypt of one variant. – David Heffernan Nov 06 '15 at 11:21

0 Answers0