Issue with Unicode !

When The text to Encrypt contain language such as :Japanese ,Thai ,Chinese ,


Then when Decrypt the text ,the result is wrong with ???

See the demo

https://mega.nz/#!8Eoj2Yxa

https://mega.nz/#!8Eoj2Yxa!Pv8Ih9ANQuitJbmPajDuZVOz4aHqyBGr4JfSmBzvnwk

Hi,
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)
Best regards,
Marion

OS:win 7 sp1

OS Language :Chinese
IDE:10.2.3
3.3.1.3

My encrypted string result in hexa is
0B6E649910308CD9E6F5FB6D07D2A0D8A72A8A0997C7924279E472BDBE469F9D201735491CC57562E8F8D68C86EF0E03C11BCEF970F1A5AEA37178AD0559A931
Ok, the problem is only an Unicode problem.

Could you send me the result of
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.

Marion
var msgLen:Integer;
s:string;
begin
s:=cnvrt1.CharToFormat(cnvrt1.StringToBuffer(edt1.Text, yesUni, msgLen), msgLen);

68656C6C6FE38193E38293E381ABE381A1E381AF20E0B8AAE0B8A7E0B8B1E0B8AAE0B894E0B8B520EC9588EB8595ED9598EC84B8EC9A946869
I have the same value, so the issue is not in StringToBuffer function.

Could you try the following code with your string s?
s := cnvrt1.StringToUnicode(cnvrt1.FormatToString(s));
And send me the new s value?

Marion

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;

end;


helloこんにちは สวัสดี 안녕하세요hi
with the old code ,after set pc's zone and langguange to english,the Decrypt result is ok!


procedure TForm1.btn1Click(Sender: TObject);
var msgLen:Integer;
s:string;
begin
//s:=cnvrt1.CharToFormat(cnvrt1.StringToBuffer(edt1.Text, yesUni, msgLen), msgLen);
//s := cnvrt1.StringToUnicode(cnvrt1.FormatToString(edt1.Text));
edt2.Text:=asncryptn1.Encrypt(edt1.Text);
end;

procedure TForm1.btn2Click(Sender: TObject);
begin
 edt3.Text:=asncryptn1.Decrypt(edt2.Text)
end;

I think the issue is in Decrypt.


1, I use my app and get the Encrypted text under OS Chinese.
2,Then I set my pc's language to English,restart pc
3,Run app,I paste the Encrypted text to edit2
4 ,Decrypt the text

I get the right result.
Hi,
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 ?
Marion
procedure TForm1.btn1Click(Sender: TObject);
var msgLen:Integer;
s:string;
begin
//s:=cnvrt1.CharToFormat(cnvrt1.StringToBuffer(edt1.Text, yesUni, msgLen), msgLen);
//s := cnvrt1.StringToUnicode(cnvrt1.FormatToString(edt1.Text));
asncryptn1.Unicode := yesUni;
edt2.Text:=asncryptn1.Encrypt(edt1.Text);
end;

procedure TForm1.btn2Click(Sender: TObject);
begin
asncryptn1.Unicode := noUni;
 edt3.Text:=asncryptn1.Decrypt(edt2.Text)
end;

OC3B2SA3SYCHU4EQ6CWS36YBVDBFHY2YX6H3SVH6GIJVMUHH5QNOPZUQRIBA23UA3XSFYYLK64IPX3GKKQPWXQ5DR7WLJIN5USDEFF4JSZGT4DDAZPPCPPY7JTO5U2TV


hello??????????????? ?????????????????? ???????????????hi


I think we are close to fixing the issue.
Do you have registered version of TMS Cryptography Pack or trial version?
Marion

I have tms all acess!



You should other compoent of Cryptography,I found some of them also have this issue!

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);


Marion

OK,NOW result is ok!

speck,salsa and so more ,also have this issue!