Which OS and which language configuration do you have?
In my PC it works, as you can see in this video : https://cyberens.fr/AESChineseCharacters.mp4
To convert Unicode characters, we use TEncoding.UTF8.GetBytes function. My encrypted string result in hexa is : BDFA44EBBB4EBC7AA518882D105205492B4EC73C96C33557F97B43F74FA588CE2010993DF6DE7560C8F6B8A5F4C97D6A0B3BE1BA5DAFA9D482BBA8DB15F19B8F
Do you have the same? (to know if the issue is in encryption or decryption)
s := Convert1.CharToFormat(Convert1.StringToBuffer(edt1.Text, yesUni, msgLen), msgLen);
with Convert1 a TConvert component, msgLen an integer and s a string?
Secondly,
you have put AES IVMode to userdefined so you have to set an IV. For
example, put the same value as the key. Without setting an IV value, the
IV value is undefined and the decryption can fail.
var msgLen:Integer; s:string; begin s:=cnvrt1.CharToFormat(cnvrt1.StringToBuffer(edt1.Text, yesUni, msgLen), msgLen); s := cnvrt1.StringToUnicode(cnvrt1.FormatToString(s)); edt2.Text:=s;
Do you put an IV value for encryption and the same for decryption? I think you are right, the issue is surely in Decrypt function. I will run more tests. Could
you try to put asncryptn1.Unicode := yesUni; before encryption and
asn1crypt1.Unicode := noUni; before decryption and send me the value of
edt3.Text ?
Ok I think the issue is in the following code in AESObj.pas at the end of the Decrypt function:
for I := 0 to outputSizeBytes^ - 1 do
{$IF (defined(MSWINDOWS) or defined(MACOS)) and (not defined(IOS))}
Result := Result + string(outputBuffer);
{$ELSE}
Result := Result + chr(outputBuffer);
{$IFEND}
Could your try to test by replacing this code with the following one?
Result := conv.CharToFormat(outputBuffer, outputSizeBytes^);
Result := conv.FormatToString(Result);