Print Page | Close Window

Issue with Unicode !

Printed From: TMS Software
Category: VCL Components
Forum Name: VCL / FMX Cryptography Pack
Forum Discription:
URL: http://www.tmssoftware.com/site/forum/forum_posts.asp?TID=12836
Printed Date: 20 Aug 2019 at 10:05am


Topic: Issue with Unicode !
Posted By: Fei Sun
Subject: Issue with Unicode !
Date Posted: 10 Jan 2019 at 7:53am
When The text to Encrypt contain language such as :Japanese , http://www.baidu.com/link?url=Z00Fzsj2Xv68r3pHdybtujEFfSHnDCFnAZRW6J173j5YpvxihvHYCCurfNzdWcv_-VcV1ZMsaLwd7sXu-DQ4xXRDWD6HXfwAyITMkS1R4P7 - Thai  ,Chinese ,

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

See the demo



Replies:
Posted By: Fei Sun
Date Posted: 10 Jan 2019 at 7:57am
https://mega.nz/#!8Eoj2Yxa


Posted By: Fei Sun
Date Posted: 10 Jan 2019 at 8:03am
http://mega.nz/#!8Eoj2Yxa!Pv8Ih9ANQuitJbmPajDuZVOz4aHqyBGr4JfSmBzvnwk - https://mega.nz/#!8Eoj2Yxa!Pv8Ih9ANQuitJbmPajDuZVOz4aHqyBGr4JfSmBzvnwk


Posted By: Marion Candau
Date Posted: 10 Jan 2019 at 9:13am
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


Posted By: Fei Sun
Date Posted: 11 Jan 2019 at 1:49am
OS:win 7 sp1
OS Language :Chinese
IDE:10.2.3
3.3.1.3

My encrypted string result in hexa is
0B6E649910308CD9E6F5FB6D07D2A0D8A72A8A0997C7924279E472BDBE469F9D201735491CC57562E8F8D68C86EF0E03C11BCEF970F1A5AEA37178AD0559A931


Posted By: Marion Candau
Date Posted: 11 Jan 2019 at 9:32am
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


Posted By: Fei Sun
Date Posted: 11 Jan 2019 at 10:00am
var msgLen:Integer;
s:string;
begin
s:=cnvrt1.CharToFormat(cnvrt1.StringToBuffer(edt1.Text, yesUni, msgLen), msgLen);

68656C6C6FE38193E38293E381ABE381A1E381AF20E0B8AAE0B8A7E0B8B1E0B8AAE0B894E0B8B520EC9588EB8595ED9598EC84B8EC9A946869


Posted By: Marion Candau
Date Posted: 11 Jan 2019 at 10:04am
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


Posted By: Fei Sun
Date Posted: 12 Jan 2019 at 1:32am
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


Posted By: Fei Sun
Date Posted: 12 Jan 2019 at 1:54am
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;


Posted By: Fei Sun
Date Posted: 13 Jan 2019 at 9:34am
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.


Posted By: Marion Candau
Date Posted: 14 Jan 2019 at 9:20am
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


Posted By: Fei Sun
Date Posted: 14 Jan 2019 at 10:10am
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




Posted By: Marion Candau
Date Posted: 14 Jan 2019 at 10:23am
I think we are close to fixing the issue.
Do you have registered version of TMS Cryptography Pack or trial version?
Marion


Posted By: Fei Sun
Date Posted: 14 Jan 2019 at 1:38pm
I have tms all acess!

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


Posted By: Marion Candau
Date Posted: 14 Jan 2019 at 1:42pm
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



Posted By: Fei Sun
Date Posted: 15 Jan 2019 at 12:47am
OK,NOW result is ok!


Posted By: Fei Sun
Date Posted: 15 Jan 2019 at 12:59am
speck,salsa and so more ,also have this issue!


Posted By: Fei Sun
Date Posted: 15 Jan 2019 at 1:02am
a


Posted By: Fei Sun
Date Posted: 15 Jan 2019 at 1:03am
33


Posted By: Fei Sun
Date Posted: 15 Jan 2019 at 1:03am
7


Posted By: Fei Sun
Date Posted: 15 Jan 2019 at 1:04am
2


Posted By: Marion Candau
Date Posted: 15 Jan 2019 at 9:03am
Thank you very much!
I will fix the bug where it is located in all components and release a new version.
Marion


Posted By: Fei Sun
Date Posted: 15 Jan 2019 at 9:32am
Be quick! 
Thank you !



Print Page | Close Window