[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Base64 problem



Hello,

The data you're trying to base64 encode is (apparently) text data.  That 
does not make sense.  The whole purpose of base64 is to encode BINARY 
(non-text) data so that it will retain it's values even after being 
transferred over a text-only channel.

Think about an image (picture) file.  A JPG for example.  This file is 
not made up of words intended for a human being to read.. Instead it's 
the values of the bytes (in binary) that are important.  If you took a 
JPG file and translated it from ASCII to EBCDIC, the picture would be 
unusuable because you would have changed the underlying bit values, and 
it'd completely change the internal format of the picture.

Not just JPG, of course...  video, sound, PDF, Excel, Word... all of 
these formats are "binary" formats where at least SOME of the bytes in 
the document aren't text and therefore will be corrupt if you translate it.

And it's not only ASCII/EBCDIC that causes a problem.   Imagine if I 
live in the USA and I send a file to someone in Poland.  The folks in 
Poland have a different "flavor" of ASCII than we have in the USA.  Some 
characters are the same, but many are different... so even if the file 
remains ASCII, parts of it will get corrupt if it's not a text document.

So that's the problem.... base64 is supposed to be the solution.  The 
idea is that the binary values are all translated into text characters 
that have been determined to be "invariant" text characters and 
therefore they exist in all codepages and character sets.  Each 
invariant character in the base64 "alphabet" corresponds to a given 
value.  That means that no matter how the text is translated, a base64 
decoder will decode the data back to the exact same binary bit values 
you started with.

So the point of base64 is to retain the exact same binary values. 
That's desirable with binary data (like JPG, movies, sounds, packed 
numbers on i5/OS, etc).  But it's NOT desirable with text, because if I 
type 'TestFranck' in EBCDIC and you want to view it in ASCII, it sure 
would be nice for it to still be made up of the letters 'T', 'e', 's', 
't' (etc).  instead of having the same underlying binary values (the 
EBCDIC binary values would look like garbage on an ASCII system, etc.)

That's exactly the problem with your test.  You've typed "TestFranck" 
into a base64 encoder on an ASCII system, and you're trying to decode it 
on an EBCDIC system.  For certain, it'll work.  But the result of the 
decode will be the ASCII hex values which will look like garbage on the 
EBCDIC system.

Likewise, if you do the encoding on the EBCDIC system you'll end up with 
a different base64 string (since the EBCDIC binary values are different 
from the ASCII ones) and when you decode it on the ASCII system, it'll 
be garbage.

So -- again -- you seem to be missing the point of base64.  Don't encode 
characters that you want to be translated from character set to 
character set -- i.e. text characters -- encoding them does not make 
sense.

Encode data that's supposed to have the same underlying BINARY values, 
even if it's encoded on ASCII and decoded on an EBCDIC system -- because 
THAT is the point behind base64.  THAT is the reason why you want to use 
base64, to protect the underlying binary values.



Franck Peter wrote:
> Hello,
> 
> I'm consuming with HTTPAPI a web service that sends back base64 encoded 
> data.
> Everything is ok until I try to decode the base64 data.
> 
> So I went to this url : 
> http://www.opinionatedgeek.com/dotnet/tools/Base64Encode/Default.aspx
> I type the text below: TestFranck
> I get the encoded base64 data : VGVzdEZyYW5jaw==
> And I made 2 little pgms ( JA005 & JA006 ) to reproduce the same with 
> the base64 encode and decode  provided by Scott.
> But it doesn't work.
> I can't see what I'm doing wrong ? Any help would be appreciate ...
> 
> Thanks
> 
> -----------------------------------------------------------------------
> This is the FTPAPI mailing list.  To unsubscribe, please go to:
> http://www.scottklement.com/mailman/listinfo/ftpapi
> -----------------------------------------------------------------------

-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------