Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
13
Erster Beitrag:
vor 1 Jahr, 6 Monaten
Letzter Beitrag:
vor 1 Jahr, 6 Monaten
Beteiligte Autoren:
CCC2, Steven Sitas, Peter Holemans, DarrenF

WD20 / WM20 CryptStandard()

Startbeitrag von CCC2 am 12.04.2016 09:58

Hi,

has anyone use CryptStandard(AES128 ) in WD20/WM20 to encrypt and decrypt in other language program on non windows OS before ?

Antworten:

it is not the problem of encrypt /decrypt (wd20/wm20) but on WD20 (windows) there's extra in which cause problem when you using other program to decrypt.

von CCC2 - am 12.04.2016 15:38
for example

I try encrypt the following text 00:00:00:00:00:00

I need to convert to utf-8 . CryptStandard(StringToUTF8(Arg_data)


when decrypt , i display in hex

encrypt using WD20

30 0 30 0 3a 0

encrypt using WM20

30 30 3a

von CCC2 - am 13.04.2016 04:52
Hi CCC2,

Is this for an iOS configuration?
In that case this 'hidden' note in the help may state why you are seeing these differences:

http://doc.windev.com/en-US/?3024031&name=length_function

Quote
WX Help System
Windows Mobile In UNICODE, each character occupies two memory bytes. Therefore, the size of a buffer containing a UNICODE string is twice the number of characters actually found in the string in Windows.


LinuxiPhone/iPad In UNICODE, each character occupies four memory bytes. Therefore, the size of a buffer containing a UNICODE string corresponds to four times the number of characters actually found in the string in Windows.


I guess you're using unicode and configurations where in one case it is represented by 2 bytes for each character and in another by 4 bytes for one character.

Cheers,

Peter Holemans

von Peter Holemans - am 13.04.2016 07:43
Hi,

The answer from me is; no, I haven't used these functions in the way you describe, BUT I think what you are describing might have something to do with Unicode? I had a similar issue recently when trying to use a text file created in Windows in a WM Android app.

von DarrenF - am 13.04.2016 07:48
Hi Darren,

on WM20 , unicode is ON , on WD20 unicode is also ON .

I try to turn unicode OFF on WD20 and test and it work .

is UNICODE ON + stringgtoUTF8 trigger bugs in WD20 ,I don't know, but on WM20 don't have such problem.

von CCC2 - am 13.04.2016 09:21
with UNICODE OFF,

decrypt AES128 on WD20 always failed . I had tried use stringtoUTF8 on the key and the data with all possible combination . none work.

von CCC2 - am 13.04.2016 09:27
here the example

it work on WM20 android and online decrypt sites but not work on WD20
you can decrypt using online (AES-128 ECB)
http://aesencryption.net/
https://www.tools4noobs.com/online_tools/decrypt/ -> select Rijindael-128
http://aes.online-domain-tools.com/ -> use hex , after decode base64 use buffertohex()


m_data64 is string = "CNp7foXV0qI6SQKshb1uBmbeyGd00YImKZPlw9GH0pRxYYis80GCaboN8XaHDo4x9aXY64OU6nT8x4tOSgUeSc9U+qeCNrRJEIblzr4RMJrpeYvCHM8acyXUHMk/AdFhEMGKeewFHM+nsUrt9nHx/lKCFenp/QxzyYWEwhJ4ro1WTLRKnxgAK14M9znflKHshwWx/rP2i7OJy0Q1nZSX1Q=="



M_key is Buffer = StringToUTF8("39060568D3DAB64D")


M_aes128 is Buffer = Uncrypt(m_data64,"",cryptNone)



Info( UncryptStandard( M_aes128 , M_key, cryptAES128,cryptECB,cryptPaddingZero) , ErrorInfo())









von CCC2 - am 13.04.2016 12:00
Here is screen shoot run on WD , UNICODE ON/OFF same




Here is screen shot WM android, UNICODE is ON





I hope someone can tell me why same code one can run another cannot ?

von CCC2 - am 13.04.2016 12:42
Hi CCC2,
the following code works for me:

///////////////////////////////////////////////////////
sMessage is Buffer = "00:00:00:00:00:00 "
// code to return a 128 Cryptkey//
// With WD we are sure that the following Cryptkey is 128//
sMypassword is string ="1234"
bufCryptKey is Buffer = HashString(HA_MD5_128, sMypassword)
// now Encrypt the message ....
bufEncrypt is Buffer = CryptStandard(sMessage, bufCryptKey, cryptAES128)
// Decrypt the message ....
sResult is Buffer = UncryptStandard(bufEncrypt, bufCryptKey, cryptAES128)
Info("decrypted message "+CR+sResult)
///////////////////////////////////////////////////////////

Note that with the code you posted, the following:
"39060568D3DAB64D"
is interpreted as 256bit on a unicode WD app and it wont work with cryptAES128.
So you would need something like cryptAES256 (which doesn't exist).
Now if you try to "downsize" this to a 128 (utf8) you will lose info (ambiguous ...)

Generally Windows treats Unicode as UTF16 and Unix Systems (and probably Android,iOS etc) treats them as UTF8. Thats why the above works in Windev Mobile ...

So the only way to be sure that the above works - on WD, WM and other systems - is let WD make the Cryptkey, with a technique like HashString (see above code).

Steven Sitas

von Steven Sitas - am 13.04.2016 13:21
Hi Steven ,

i confused

from what I know , AES128 secret key is 16 bit , if 1 character 1 byte would be 16 character. the secret key I use is 16 bytes

if as you said
"39060568D3DAB64D" is interpreted as 256bit on a unicode WD app and it wont work with cryptAES128.

how come when I encrypt message and send to other party to decrypt (non-windev) , it work if I set UNICODE OFF (ANSI) in WD ?

but even with UNICODE OFF (ANSI) in WD , how come i unable to decrypt message encrypted by other party (non-windev) ?

von CCC2 - am 13.04.2016 16:10
Hi CCC2,
there is an example in WD20 called WD Data encryption.
It is in the training examples (Not the unit examples).

Try your case there and see if it works ....
1) If it doesn't work as expected, you can use this example and contact PCSoft.
We all know how PCSoft tech support asks for CODE or applications that show a problem.

2) If it works there, study the code.
The bad thing is that it uses classes and that makes it (at least for me) unnecessary complicated.
They should have avoided using classes in the examples, except ofcourse when they wanted to show WD object oriented features.

Steven Sitas

von Steven Sitas - am 13.04.2016 19:02
Hi Steven ,

I solved the problem :cheers:



the WD Data encryption, as expected throw same error

my solution is . I google to c# code . the generate library . import the assemblies into WD20. then call the function.

it's not the problem of the password as you suspect . on C# the password is working with UNICODE ON

I believe there bugs in WD20 CryptStandard/UncryptStandard .



Quote

1) If it doesn't work as expected, you can use this example and contact PCSoft.
We all know how PCSoft tech support asks for CODE or applications that show a problem.


sorry PCSoft tech support don't like me. they never reply back. not even reply whether they can replicate the problem or not .
The bugs is there , sooner or later someone will encounter . let wait that person to report .

von CCC2 - am 14.04.2016 07:43
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.