Whenever you release a new version, I've had compatibility issues with previous versions and I need to modify my program.
I am now unable to decrypt texts created in versions prior to 5.1.1.0;
I upgrade from version 5.1.0.3 to 5.1.1.0 and when opening my project I received an error stating that the KeyLength property (of TAESEncryption) did not exist.
This property doesn't appear in the Object Inspector, but I can set it in the code.
I set it to the value I used, kl256, but I can't decrypt the encrypted texts in version 5.1.0.3.
I downgrade to version 5.1.0.3 and was able to decrypt the texts.
How can we solve this problem?
The properties of both versions are the same (except for the KeyLength, which I had to set in version 5.1.1.0 via code).
The KeyLength property: I moved the TKeyLength type frome AES files to CryptoConst.pas so that it could be shared across the library without redefining it in several places. It looks like that this ‘external’ declaration removed the property from the graphical component. I was not aware of that ‘side effect’ and that was certainly not desired. Moving this propoerty back is not my prefered option at this stage.
The second issue is the impossibility to decrypt text encrypted with 5.1.0.3. I may have missed something, but here is a short code with NIST test vectors:
String encryption and decryption with the AES 256 bit key Expected cryptogram: 5c9d844ed46f9885085e5d6a4f94c7d7 5C9D844ED46F9885085E5D6A4F94C7D7 014730F80AC625FE84F026C60BFD547D Original text: 014730F80AC625FE1EF026C60BFD547D
I use a simple process to encrypt/decrypt the texts.
To encrypt, I use the function:
Function TMenu_Sistema.Crypt_Text(Const pText: String): String;
Begin
rmCrypt.InputFormat:=TConvertType.raw;
rmCrypt.OutputFormat:=TConvertType.base64;
Result:=rmCrypt.Encrypt(pText);
End;
To decrypt:
Function TMenu_Sistema.Decrypt_Text(Const pText: String): String;
Begin
rmCrypt.InputFormat:=TConvertType.base64;
rmCrypt.OutputFormat:=TConvertType.raw;
Result:=rmCrypt.Decrypt(pText);
End;
rmCrypt is a TAESEncryption in the main form, and I set the key when the application starts:
procedure TMenu_Sistema.FormCreate(Sender: TObject);
Begin
:
:
rmCrypt.Key:=c_Key; //String var with key
:
:
End;
Do you see anything in this code that might prevent texts encrypted with version 5.0.1.3 from being decrypted with version 5.1.1.0?
No, except for the KeyLength that may be set to a different default value between the two versions. Try to force it to kl256 with the new version, before setting c_key, to validate/invalidate this lead.
OK. If you could send me an example with exact values, that would help a lot. It may be that the IV is not set to the right format in one of the operations.