Welcome! Log In Create A New Profile

Advanced

[WM/WB26] - Encrypting/Decrypting

Posted by JP 
JP
[WM/WB26] - Encrypting/Decrypting
November 29, 2021 12:27PM
Hi All

I want to encrypt some text and convert that to a QRCode in WebDev 26. The QRCode will be displayed on a web page. Then I want to use a WinDev Mobile 26 app to read the QRCode and decrypt it. But the final decrypt fails without any useful information. Here is some sample code;


WebDev on Windows O/S:

// Create the encryoted string and set value of QRCode

bufClé is Buffer = HashString( HA_MD5_128 , "mot de passe" )
bufMessage is Buffer = "Message à crypter"
bufCrypte is Buffer = EncryptStandard( bufMessage , bufClé , cryptAES128 )

BCOD_QRCode..Value = bufCrypte


Then in WinDev Mobile on Android O/S:

bufClé is Buffer = HashString( HA_MD5_128 , "mot de passe" )
bufCrypte is Buffer = bcQRCode..Content // The content from the scanned QRCode
bufMessage is Buffer = DecryptStandard( bufCrypte , bufClé , cryptAES128 )
Info( bufMessage )


Problem is that in WinDev Mobile the decrypted message is blank. It does not decrypt properly.


I have also tried to Base64 encode the encrypted buffer and use that as the QRCode content and then, of course, decode the Base54 encoding before trying to decrypt but that also did not work. I have confirmed that the Base64 encoded/decoded texts are the same.

Any suggestions?
Argus
Re: [WM/WB26] - Encrypting/Decrypting
November 29, 2021 12:51PM
classic problem ansi/unicode

in your code, "mot de passe" is an ansi string by default on windows, and a unicode one in mobile... the result of an encryption/decryption is therefore different.

When you communicate between different system, it is mandatory to put all strings inside precisely types variable:
MyString is ANSI string="mot de passe"
then use MyString

This way, you do the same thing on all sides... THis is true for ALL strings, weather declared as variable (you need to specify the same type everywhere) or litteral ones (and beware of the constants too)
JP
Re: [WM/WB26] - Encrypting/Decrypting
November 29, 2021 01:54PM
[UPDATE] - Argus, thanks, I have worked it out. Needed to do an additional buffer to ANSI String conversion at the end. Thanks.


------

Argus

Thanks for the reply. I was thinking its something like that but still cant get it to work ..


In WebDev I have this code to set up the QRCode:

sPassword is ANSI string = "password"
bufClé is Buffer = HashString( HA_MD5_128 , sPassword )
bufMessage is Buffer = "Message to encrypt"
bufCrypte is Buffer = EncryptStandard( bufMessage , bufClé , cryptAES128 )
sEncoded is ANSI string = Encode( bufCrypte , encodeBASE64 )

BCOD_Competition_QRCode..Value = sEncoded


In WinDev Mobile I have this code in the QRCode decoding routine:

sEncoded is ANSI string = bcQRCode..Content
sPassword is ANSI string = "password"
bufClé is Buffer = HashString( HA_MD5_128 , sPassword )
bufCrypte is Buffer = Decode( sEncoded , encodeBASE64 )
bufMessage is Buffer = DecryptStandard( bufCrypte , bufClé , cryptAES128 )

Info( bufMessage )


Where do I go wrong?

Thanks



Edited 5 time(s). Last edit at 11/29/2021 02:09PM by JP.
Re: [WM/WB26] - Encrypting/Decrypting
November 30, 2021 11:21AM
HI,

does anyone ever solved this problem? i can get it to work with Android but not with IOS.

thanks
JP
Re: [WM/WB26] - Encrypting/Decrypting
November 30, 2021 02:30PM
Marcov

I got it working on Android with Argus' help. Post your code for us to see. Maybe something comes to mind.
Re: [WM/WB26] - Encrypting/Decrypting
December 01, 2021 09:56AM
hi,

SERVER:
sRispShop is unicode string
sRispShop = Encode(SQLGetCol("QRY1", 3),encodeBASE64NoCR)

I create the json and send it


CLIENTE:
//FROM Server RECIVE JSON
vResultJSON is JSON = cMyResponse.Content
sFromServer is unicode string
vParameters is Variant

//DECODE JSON
sFromServer = cMyResponse.Content
vParameters = JSONToVariant(vResultJSON)


// WORK ON ANDROID DEVICE AND EMULATOR, IN IOS WORK ONLY IN EMULATOR
sXshop is unicode string= vParameters.Shop
Info("shop "+sXshop) // is ok show a corretc string
sXshop2 is Buffer=Decode(sXshop,encodeBASE64NoCR)
Info("shop "+ sXshop2) // sXshop2 shows an empty string



Edited 1 time(s). Last edit at 12/01/2021 09:58AM by marcov.
JP
Re: [WM/WB26] - Encrypting/Decrypting
December 01, 2021 10:45AM
marcov

As an initial test I would remove the encode()/decode() to make 100% sure I am getting the content before doing any encoding stuff. If that works then we know it is the encode()/decode() functions. Then I would try different encode()/decode() options to see if they all dont work or only some. If that still fails on encode()/decode() I would contact PCSoft because I think it would then imply a bug.
JP
Re: [WM/WB26] - Encrypting/Decrypting
December 01, 2021 10:51AM
marcov

Perhaps a stupid suggestion but what happens if you make sXshop2 a unicode string (not a buffer)?
Argus
Re: [WM/WB26] - Encrypting/Decrypting
December 01, 2021 02:57PM
If I remember correctly, for IOS, you have to encode in UTF8
Re: [WM/WB26] - Encrypting/Decrypting
December 02, 2021 09:53AM
hi,

i tried to change the encoding with, but now the string is sent without encode

sRispShop = Encode(SQLGetCol("QRY1", 3),encodeURLFromUTF8)

encodeURLFromUTF8 is only with UTF8 i have found....

i have tried all kinds of encode/decode and on IOS none seem to work.



Edited 1 time(s). Last edit at 12/02/2021 10:11AM by marcov.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: