Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
12
Erster Beitrag:
vor 1 Jahr, 8 Monaten
Letzter Beitrag:
vor 1 Jahr, 6 Monaten
Beteiligte Autoren:
CCC2, Danny Lauwers, Steven Sitas, Fabrice Harari, Arie

[wm20 - android] alternate function for convert binary to text other than base64

Startbeitrag von CCC2 am 23.03.2016 12: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?27131,590592


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 ?

Antworten:

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.

von Arie - am 23.03.2016 13:25
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

von Fabrice Harari - am 23.03.2016 13:29
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

von Danny Lauwers - am 23.03.2016 13:38
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

von Steven Sitas - am 23.03.2016 13:45
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?file_id=88210967855698166427

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



von CCC2 - am 24.03.2016 03:08
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.

von CCC2 - am 24.03.2016 03:17
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

von CCC2 - am 24.03.2016 08:07
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 for the Base64 Result, the result is the same !

Very Strange ? :confused:

Danny

von Danny Lauwers - am 24.03.2016 08:11
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.

von CCC2 - am 26.03.2016 16:32
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?LANGUE=US

Hope you get it working !
Danny

von Danny Lauwers - am 29.03.2016 13:06
Hi,

Problem still Persist in WM21 .

even though I did encrypt AES128 first before encode base64. the problem still occur .

the lucky part is because of missing bytes cause decryption AES128 fail which will trigger error.

I give up .

von CCC2 - am 27.04.2016 12:47
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.