PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → [wm20 - android]  alternate function for convert binary to text other than base64
[wm20 - android] alternate function for convert binary to text other than base64
Iniciado por guest, 23,mar. 2016 13:43 - 10 respuestas
Publicado el 23,marzo 2016 - 13:43
Hi,

I in urgent need to find alt function to convert binary to text after I found bugs in crypt(base64) .

crypt(base64) cause lost of bytes. read the last post
http://27130.foren.mysnip.de/read.php…


function I can think out :
- UUEncode() but this function is not available in android.
- convert to hexadecimal -> extreme slow
- Base85 -> WM not support
- crypt(buffertohex(img), "",cryptNone) -> solve problem of lost bytes but generate very big files


any suggestion ?
Publicado el 23,marzo 2016 - 14:25
Where do you images come from? Your own backoffice system?

I get images from a WB-server using a httprequest. The webserver answers with a StringDisplay() of the raw data and finally in WM the HTTPGetResult(httpResult) is saved using fSaveBuffer.

Never had any problem after thousand of images. And even PDF, Excel and Word documents.

So I wonder if you need the base64 stuff in the first place.

However: Google for base64+android and you find plenty of Java examples.
Publicado el 23,marzo 2016 - 14:29
Hi

If you are sure it's a WM bug, than my suggestion would be to create a very small example proect to demonstrate it and send it to pcsoft.

In cases like that (obvious bug perfectly documented and blocking), I generally get a correcting patch in just a few days.

Best regards
Publicado el 23,marzo 2016 - 14:38
Hi,

I also use base64 stuff on android, and until now I have not found any problems with it. Maybe if you can put the base64 string and what the output should be I can test it !

Danny
Publicado el 23,marzo 2016 - 14:45
Hi,
have you already a bunch of base64 strings and you wan't to assign them to an image OR
are YOU producing the base64 strings?
It isn't clear from your post.

Here is code that works in WinDEV20 and WinMOBILE20 (I use it with webservices)

bufImageString is Buffer
bufEncryptedImage is Buffer
bufEncryptKey is Buffer = HashString(HA_MD5_128, "xxxx")

bufImageString=yourfile.Drawing // assign an IMAGE (binary memo) to the buffer
bufEncryptedImage = CryptStandard(bufImageString,bufEncryptKey,cryptAES128)

bufUnEncryptedImage is Buffer
bufUnEncryptedImage = UncryptStandard(bufEncryptedImage,bufEncryptKey,cryptAES128)

yourfile.Drawing=bufUnEncryptedImage

//////////////////////
Note the use of CryptStandard and UncryptStandard

Steven Sitas
Publicado el 24,marzo 2016 - 04:08
Hi,

todo test

you can download original image file from here. put in /sdcard/Picture folder of your device

http://s000.tinyupload.com/index.php…

create a window with 2 edit control , called it edt_before and edt after

paste this code in "end of initialization of win_test"
----------------------------------------------------------------------------------------
M_imgfile is Buffer
M_img64 is Buffer
M_img_after is Buffer

M_imgfile = fLoadBuffer( "/sdcard/Picture/ArrowDown.png" )

EDT_Before..Value = BufferToHexa(M_imgfile)

M_img64 = Crypt(M_imgfile,"",cryptNone)

M_img_after = Uncrypt(M_img64, "", cryptNone)

EDT_After..Value = BufferToHexa(M_img_after)

fSaveBuffer("/sdcard/Picture/ArrowDown_after.png",M_img_after)
-------------------------------------------------------------------------------------------

here the screen shot ArrowDown.png , pay attention to the last 4 bytes AE 42 60 82

use hex edit to open the


after running the program, take note that last 4 bytes AE 42 60 82 is missing in edt_after



I compare the original image file and image file created using fsavebuffer() using online diffnow.com
Publicado el 24,marzo 2016 - 04:17
Hi,

for png, missing the byte, some app can still display the content but for archive files (zip) or pdf , missing bytes will cause unable to extract or open.

my purpose to convert to binary64 is because The JSON format natively doesn't support binary data. The binary data has to be escaped , method to escape binary data is to use Base64.
Publicado el 24,marzo 2016 - 09:07
Hi,

Thanks Steven Sitas , for suggestion of using CryptStandard(cryptAES128).

By adding CryptStandard(cryptAES128) before the crypt(base64) . This method prevent lost bytes in crypt(base64) .

:cheers::cheers: I finally can have good sleep
Publicado el 24,marzo 2016 - 09:11
Hi,

I tested you principle, and I must say I do not have this problem. My output looks like this

[attachment 1896 Screenshot-1.png]

And I use this code

buf1 is Buffer sBase64 is string buf1 = fLoadBuffer(fBuildPath("/storage/sdcard0/DCIM","ArrowDown.png")) IMG_NoName1 = buf1 EDT_NoName1 = BufferToHexa(buf1) sBase64 = Crypt(buf1,"",cryptNone) buf1 = Uncrypt(sBase64,"",cryptNone) EDT_NoName2 = BufferToHexa(buf1) EDT_NoName1..CursorEnd = Length(EDT_NoName1) EDT_NoName2..CursorEnd = Length(EDT_NoName2)
I use Android target 4.03 and it is running on an Android 4.1.2 Device
My Android SDK Build-tools is version 23.0.2
Even if I use a buffer instead of a string, the result is the same !

Very Strange ? :confused:

Danny
Publicado el 26,marzo 2016 - 17:32
Hi Danny,

android device
Phone -> 4.2.2
Tablet -> 4.4.2

android sdk
sdk tools 23.0.2
platform-tools 23.0.1
build-tools 23.0.1

wm20 minimun target 4.2

I tried to upgrade the sdk to the latest , which is big mistake. after upgrade. WM20 compile failed.
Publicado el 29,marzo 2016 - 15:06
Hi,

I think you need a hotfix to support the latest SDK if I remember correctly !

http://stg.webdev.info/publicationSt_WEB/uk/miseajourst.awp…

Hope you get it working !
Danny