Empty result?

Using code below with Delphi 13.1 - 64bit application - TMS Crypto 5.1.1.9

procedure TLicense.DoCreateEncryption;
begin
FEncryption := TAESEncryption.Create(nil);
FEncryption.AType := TAESType.atCBC;
FEncryption.KeyLength := TAESKeyLength.kl256;
FEncryption.OutputFormat := TConvertType.hexa;
FEncryption.PaddingMode := TPaddingMode.PKCS7;
FEncryption.IVMode := TIVMode.rand;
FEncryption.Unicode := TUnicode.yesUni;
FEncryption.Key := 'QFGZDJAEREFJHFVRUHOLQTSIYDPETOZJ'
end;

function TLicense.DoDecrypt(const Encryption: string): string;
var
lEncryption: string;
lConvert: TConvert;
begin
lConvert := TConvert.Create;
try
lEncryption := lConvert.ToCharString(Encryption);
try
FEncryption.outputFormat := TConvertType.raw;
Result := FEncryption.Decrypt(lEncryption);
except
// not the nicest way to handle an exception, but the user may not be aware of this
on E:ECryptoPack do
Result := '';
end;
finally
lConvert.Free;
end;
end;

function TLicense.DoEncryptKey: string;
begin
  Result := FEncryption.Encrypt(User.Key);
end;

Why is the result of DoDecrypt('EF2B1D8A4414D75ECB3D9654876AD26FB793F109B5AC66C2D8AF2851285F2515') empty while the result of DoEncryptKey is exactly EF2B1D8A4414D75ECB3D9654876AD26FB793F109B5AC66C2D8AF2851285F2515 ?

What am I doing wrong here?

Regards,

Filip

Hi,

No idea.

I did this with a TButton on a Form:

  1. modified encrypt
function TForm1.DoEncryptKey: string;

begin
Result := FEncryption.Encrypt('TestKey'); // for instance
end;
  1. with your other functions:

procedure TForm1.TestBtnClick(Sender: TObject);
begin
DoCreateEncryption;
FResult := DoEncryptKey;
Memo.Lines.Add(FResult);
Memo.Lines.Add(DoDecrypt(FResult));
end;

and got the clear text back on every attempt.

Does User.Key contain specific characters?

Regards,

bernard

Hi Bernard

Thanks for the response...
I have been debugging all day and just found out I was using an "old" license-file (TLicense).

So, this was completely my mistake.

Sorry for the inconvenience.

Regards,

Filip

No problem!