Errors after updating to version 5

TAESencryption 5.0.9.9

I cannot decrypt anymore using my old code, I get an error "Invalid operation -208". If I set Input to hexa and output to raw I can decrypt and it's readable. It's ordinary text saved to a database and has worked fine for years.

I can also encrypt with above settings, but when I try to decrypt I get an error "-207".

So it's breaking changes from version 4.x to 5.x. Please make an article with detailed descriptions on how to fix this in our code, I'm sure others have similar problems?

What exactely is Input? Is it input to the AES component to be encrypted? My text to be encrypted is text from a TEdit component.

What is Output, is it output from the AES component to be decrypted?

I'm sure it's simple for you, but not for me :grinning_face: I have spent two days now, and I am not able to solve this.

Hi, this most likely a conversion issue as explained in similar posts (error 207/208/201). Please send me a short project at bernard[at]tmssoftware[dot]com for analysis.
Regards,

Hi

My code is extremely simple.

I put a TAESencryption component on the form and keep everything default (I have no clue what the different properties do/is).

AType, atCBC
Endian, BigEndian
IV, blank
IVMode, rand
Keylength, kl128
Outputformat, Raw
PaddingMode, PKCS7
UniCode, YesUni

Then I call this in a button click

s:='';
s:=myEditField.Text;
s:=myAESencryption.encrypt(s);

Is it possible to receive an installer with the 4.xx version? It does the job for my purposes. If not it would be great if you could supply sample code how to decrypt text encrypted with version 4.x and at the same time also encrypt/decrypt text using version 5.x.

At the moment I can only decrypt old text and not encrypt any new text (it can't be decrypted using the same code/settings)

I have a LOT of records, and I mean a LOT, in the database encrypted using version 4.

Hi,

Version 4.3.3 is in your product list.

This works fine:

var
 Laes: TAESEncryption;
 LCipher, LResultat: string;
 
begin
  Laes:= TAESEncryption.Create;
  try
    Laes.AType:=              atCBC;
    Laes.KeyLength:=          kl128;
    Laes.Unicode :=           yesUni;
    Laes.Key:=                '1234567890123456'; // 'raw' key
    Laes.inputFormat :=       raw;
    Laes.OutputFormat :=      raw;
    Laes.PaddingMode:=        TpaddingMode.PKCS7;
    Laes.IVMode:=             rand;
    // Encrypt
    LCipher:= Laes.Encrypt('Any string for a test'); // raw string, unicode
    MainMemo.Lines.Add('Cryptogram: ' + LCipher);
    // Decrypt
    Laes.Decrypt(LCipher, LResultat);
    MainMemo.Lines.Add('Cleartext: ' + LResultat);

  finally
    Laes.Free;
  end;

It may be that your strings were stored as 'hexa' in 4.3.3. If yes, you then need to convert them before decryption.

var
 Laes: TAESEncryption;
 LCipher, LResultat: string;
 Conv: TConvert;

begin
  Laes:= TAESEncryption.Create;
  Conv := TConvert.Create(hexa);
  try
    Laes.AType:=              atCBC;
    Laes.KeyLength:=          kl128;
    Laes.Unicode :=           yesUni;
    Laes.Key:=                '1234567890123456'; // 'raw' key
    Laes.inputFormat :=       raw;
    Laes.OutputFormat :=      raw;
    Laes.PaddingMode:=        TpaddingMode.PKCS7;
    Laes.IVMode:=             rand; // will be converted to hexa in the cryptogram
    // Decrypt
    // inputFormat is raw, convert Cryptogram that was in hex
    Conv.AType := hexa; // not needed as we created 'conv' with 'hexa'
    LCipher := Conv.FormatToChar(LCipher); // your own encrypted text in LCipher here
    Laes.Decrypt(LCipher, LResultat);
    MainMemo.Lines.Add('Cleartext: ' + LResultat); 

    // Encrypt
    LCipher:= Laes.Encrypt(LCipher); // raw string, unicode
    MainMemo.Lines.Add('Cryptogram: ' + LCipher); // raw text

  finally
    Conv.Free;
    Laes.Free;
  end;

Example:

Cryptogram: 6’.pÆÔ¬˜t™’¥°’j'e²Š7fiÙ^\Ýk:–Þ™µ6Š»¥N+óøÆ/³Ñï
Cleartext: Any string for a test

Thanks Bernard, I will try later today.

Thanks for your swift response :slightly_smiling_face: