Invalid Operation: -207

After updating to version 5.0.9.4, I started receiving error -207 when decrypting strings encrypted by the previous version.

I reverted back to version 4.3.3.0 and the problem no longer occurred.

What could be the cause of this problem?

I´m using Delphi 12.3 (Windows 11 Pro - 64 Bits).

Most likely the input format for decryption for either data or key or IV is not as expected.
For instance, if outputFormat is hexa for encryption, then inputFormat for decryption shall be hexa and all parameters (data, key, IV) shall be in hexa. If not, just convert them (raw is usually fine) before decrypting.

Shouldn't the new version maintain compatibility with the previous version?

In version 4.3.3.0 the TAESEncrryption configuration was:

In new version:

If I switch to raw, the -207 error does not occur, but it cannot decrypt the texts generated in version 4.3.3.0.

And new encrypted texts in the new version cannot be decrypted by previous versions of my application.

I tried various combinations of InputFormat and OutputFormat, but I couldn't maintain backward compatibility.

Based on the configuration screenshot for version 4.3.3.0, what is the correct configuration for version 5.0.9.3 so that texts encrypted by the current version can be decrypted by the previous version?

Can you provide some code please?

By making an example program I managed to solve the problem.

In the new version 5, it is necessary to modify the InputFormat and OutputFormat parameters whenever I change operations.

Before encrypting, I now need to define:

TAESEncryption1.InputFormat:=TConvertType.raw;
TAESEncryption1.OutputFormat:=TConvertType.base64;

And before decrypting I need to indicate the opposite:

TAESEncryption1.InputFormat:=TConvertType.base64;
TAESEncryption1.OutputFormat:=TConvertType.raw;

In previous versions, it was enough to set the OutputFormat to hexa once in the entire application (it worked for encryption and decryption).

I suggest putting this information in the documentation as other users may have the same problem.

I would like to know if the {$DEFINE IDEVERSION1021} option in tmscrypto.inc is still used and, if it is, I would like to suggest that you leave this option active by default.

Thank you.

I have a similar problem with the news TMSCrypto but I use

TEncryptedIniFile.Create

With the current version I can not decrypt ini files written with previous version.

How can I solve the problem with this object?

Björn

Very good.
Yes, the 'inputFormat' property is new compared to the previous version and provides more options.

TmsCrypto.inc is no longer used.

What are the parameters (mode, IV type) and 'outputFormat' value?

I understand that since TmsCrypto.inc is no longer used, version 5 doesn't require RandomDLL to run on Windows 64.

Is this correct?

That is correct.
Random services are now in RandomCoreW.pas for Windows and RandomCoreL.pas for all other systems.
Because this makes things complicated for Smart Setup, I have already merged these 2 files into RandomCore.pas. This will be available in the next release, next week or so.

None.

iIni := TEncryptedIniFile.Create(AutoLoginFileLocationExp, ikey);

as in previous version.

Found extended
iIni := TEncryptedIniFile.Create(AutoLoginFileLocationExp, ikey, yesNo, hexa);
but couldn't get the right prarams to be compatible to previous version.

Can you help?

It looks like your output will be in hexadecimal. Try to convert it to 'raw' before decrypting.

Two options:

inputFormat := hexa'; // but the key also need to be in hexa
outputFormt := raw;
then decrypt

or, load the file content in a string s.
Conv: TConvert;

Conv := TConvert.Create(hexa);

s := 'whatever the file contains';

s := Conv.FormatToChar(s);

now decrypt s

Tip: do not use anything than 'raw' when encrypting files

Hm, I do not realy understand.
TEncryptedIniFile is part of your product.

The idea is not to decrypt the content of the whole file but only when accessing a value.

After looking in the source code: the TEncryptedIniFile uses
inputFormat := raw';
outputFormt := hexa;

output can be changed via parameter, but input is fixed.

I need to update this file issue a new version.
In the meantime, you can do this if the fix is urgent:

  • in the class, add FInputFormat: TConvertType;
  • change the create #3 to
  • constructor Create(const FileName: string; const Key: string;
    const Uni: TUnicode; const InputFormat, OutputFormat: TConvertType); overload;
  • in each create, add: FInputFormat := InputFormat;
  • in the LoadValues and UpdateFile method, add: aes.InputFormat := InputFormat;

This should help.

Sorry, in all 'create', FInputFormat: raw; and
in LoadValues and UpdateFile methods, add: aes.InputFormat := FInputFormat;

Hm. I've added
aes.inputFormat := hexa;
in LoadValues and UpdateFile for the moment and converted the key to hexa but it's not compatible to the prior version and I can't read the old files.

OK, I will have a look.

Could you provide an example with 4.3.3 and a 'fake' key?

Yes, of course.
It'll take a while and I'll send it via mail.