I’m also experiencing issues with encryption/decryption using TAESEncription – it no longer works for me.
During my research, I found this forum entry:
Invalid Operation: -207 - #14 by Reimer_Bjorn
To investigate further, I tried running the demo project CryptoDemo (located in Products\tms.vcl.crypto\Demos\VCL
).
Unfortunately, it does not run correctly either:
- In the DPR file, FastMM4 is not found and must be removed:
program CryptoDemo;
uses
FastMM4,
Vcl.Forms,
- In the unit
uCryptoDemo
, the unit ECIES is not found and must also be removed:
unit uCryptoDemo;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Diagnostics, System.DateUtils, System.UITypes, Vcl.FileCtrl,
System.Classes, Vcl.Graphics, System.TimeSpan, System.IOUtils,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Imaging.pngimage, Vcl.ExtCtrls,
Vcl.Buttons, Vcl.StdCtrls, Vcl.ComCtrls, AnsiStrings, Shellapi,
CryptoConst, AESObj, RSAObj, ECCObj, Argon2d, HashObj, PBKDF2, SalsaObj,
SPECKObj, MiscObj, X509Obj, XAdESObj, CAdESObj, PAdESObj, AdESObj, PKCS11Obj,
TMSEncryptedIniFile, CryptBase, tlsh, Curves, ECIES;
After applying these corrections, the program compiles and runs.
On the AES tab, I entered a key and some text. Encryption seems to work, but during decryption the key length is flagged as invalid – even though the key is correct (see screenshot).
In my own program I get this exception:
Exception: Invalid Operation : -208
If I apply the suggested code changes from the forum entry above, I then get the error that the key length is invalid – again, even though the key is correct.
(The key is actually already in hex format, but the “-208” error message appears before conversion.)
Here’s my current decrypt function:
function Tdm.DecryptStr(AString: String): String;
begin
try
var Conv: TConvert;
Conv := TConvert.Create(hexa);
AES.AType := atCBC;
AES.KeyLength := kl256;
AES.OutputFormat := hexa;
AES.Key := Conv.FormatToChar(FKey);
//AES.Key := FKey;
AES.PaddingMode := TPaddingMode.PKCS7;
AES.IVMode := TIVMode.rand;
AES.Unicode := yesUni;
Result := AES.Decrypt(Astring);
except
on E:Exception do
begin
ShowMessage(E.ClassName+': '+E.Message);
end;
end;
end;
How can this be fixed as simply as possible?