Issue with Decryption in TMSCryptography v5.0.9.5 (Error -208)

Hello,

The following code:

var
  Laes: TAESEncryption;
  LCipher, LResultat: string;
begin
  Laes := TAESEncryption.Create;
  try
    Laes.AType := atCBC;
    Laes.KeyLength := kl256;
    Laes.Unicode := yesUni;
    Laes.Key := '12345678901234567890123456789012';
    Laes.OutputFormat := hexa;
    Laes.PaddingMode := TpaddingMode.PKCS7;
    Laes.IVMode := TIVMode.rand;

    // Encrypt
    LCipher := Laes.Encrypt('test');
    ShowMessage(LCipher);

    // Decrypt
    Laes.Decrypt(LCipher, LResultat); // Also tested: Laes.Decrypt(LCipher);
    ShowMessage(LResultat);

  finally
    Laes.Free;
  end;
end;

The line:

Laes.Decrypt(LCipher, LResultat);

randomly raises the following error in approximately 99% of cases:

"Invalid Operation; -208"

This happens under Delphi 11.3 and Delphi 12.3 (both 32 bit and 64 bit VCL) using version v5.0.9.5 of the Cryptography Pack.
This exact same code worked fine with version 4.x.

Moreover, this snippet is a direct copy/paste from your TMSCryptographyPack.pdf documentation, § AES (modes ECB-CBC-OFB-CTR-CTS).

Could you please investigate this issue or confirm if there’s a workaround or regression fix?

Thank you.

That is indeed an inputFormat issue. You can fix it this way:


procedure TDemoForm.AESDebugBtnClick(Sender: TObject);
var
 Laes: TAESEncryption;
 LCipher,LResultat: string;
 Conv: TConvert;

begin
    Laes:= TAESEncryption.Create;
    Conv := TConvert.Create();
    try
        Laes.AType:=              atCBC;
        Laes.KeyLength:=          kl256;
        Laes.Unicode :=           yesUni;
        Laes.Key:=                '12345678901234567890123456789012'; // 'raw' key
        Laes.inputFormat :=       raw;
        Laes.OutputFormat :=      hexa;
        Laes.PaddingMode:=        TpaddingMode.PKCS7;
        Laes.IVMode:=             rand; // will be converted to hexa in the cryptogram
        // Encrypt
        LCipher:= Laes.Encrypt('my little test'); // raw string, unicode
        MainMemo.Lines.Add('Cryptogram: ' + LCipher); // hex output
        // Decrypt
        // inputFormat is raw, convert Cryptogram that was in hex
        Conv.AType := hexa;
        LCipher := Conv.FormatToChar(LCipher);
        // we want the output as a raw string (or whatever else)
        Laes.OutputFormat := raw;
        Laes.Decrypt( LCipher,LResultat);
        MainMemo.Lines.Add('Cleartext: ' + LResultat);

    finally
      Conv.Free;
      Laes.Free;
    end;
end;

Hello,

Thank you for your reply.

Could you please update all the relevant code samples in your TMSCryptographyPack.pdf to reflect the changes introduced in version 5.x?

Also, it would be very helpful to clearly mention somewhere (preferably at the beginning of the documentation or in a changelog) that there is a major breaking change between versions 4.x and 5.x. This would help avoid confusion and save time for developers updating their projects.

In my case, I’m using these components inside TMS Scripter, so I was troubleshooting at the scripting level and digging through my own library functions before realizing the issue was due to a change in the core component behavior.

Thank you for your attention.

Best regards,

Hello,

For the manual: yes, most examples will be updated for the next release. That is something I overlooked.
The 'inputFormat' addition was mentioned in a couple of places, but obviously not clearly enough. I'll try to improve that.

In the manual:
( NOTE 3: some APIs have been changed to ensure better uniformity across cryptographic interfaces and Users may have to adjust existing code to take those changes into account, especially with the new ‘inputFormat’ property (see README-FIRST.txt).)

Regards,