Error in Data Encryption

Today I have updated TMS Cryptography Pack from 4.3.3.0 to 5.1.0.1.
My AES encryption procedure (which was working ok for some years) now generates an exception, when I call aes.Encrypt(s) an encryption fails.

function EncodeAES2String (const s, Key:string) : string;
var
aes : TAESEncryption;
i : Integer;
iv : string;
begin
Result := '';
aes:= TAESEncryption.Create;
try
aes.AType := atCBC;
aes.KeyLength := kl256;
aes.Unicode := yesUni;
if Key = '' then
aes.Key := BriSec32String
else
aes.Key := Key;
aes.OutputFormat := base64;
aes.PaddingMode := TpaddingMode.PKCS7;
iv := '';
for i := 1 to 16 do
iv := iv + Chr(0);
aes.IV := iv;
aes.IVMode := TIVMode.userdefined;
Result := aes.Encrypt(s);
finally
aes.Free;
end;
end;

Hi, what is the exception and what is the key size?

Key size is 32, for example 'abcdEFGHijklMNOPQRST$1234567890#'
The exception is 'Invalid Operation : -207'
Error appears also in version 5.1.0.2

Works fine with me, see attachment with decryption. You may have an install issue.

NoBug.zip (73.3 KB)

Thank you for quick check!
When I run the program and click Encrypt, I receive the error, when I call Decrypt command:
error : in AES, the cipher text cannot be decrypted because the padding is not correct!

Well, you have another problem as this project should run with all 5.x versions.
I recommand you uninstall TMS CP, clean up DCUs and reinstall.

Thank you,

I cleaned up DCU, then I added the conversion of result string to base64 and it works again - thank you!

Good!

The issue with DCUs is quite frequent. I recommand you uninstall libraries and clean up all DCUs when installing a new version of ANY library, not only TMS CP.