xsharp.eu • X# Substitutions for EncodeBase64 and DecodeBase64 - Page 2
Page 2 of 2

X# Substitutions for EncodeBase64 and DecodeBase64

Posted: Wed Sep 30, 2020 1:40 pm
by wriedmann
Hi Arne,
I have too some problems with these encodings....but I try to not use the VO compatible functions when working with encodings, but using instead own functions where I have the encoding under control.
The main problem is that in VO you can use such strings also to save and restore bitmaps or other binary data where cou cannot in X#.
Personally I do think that the development team cannot do anything here - the Ansi vs Unicode problem is not easy to solve (or not possible to solve at all without touching code).
Wolfgang

X# Substitutions for EncodeBase64 and DecodeBase64

Posted: Mon Oct 12, 2020 2:30 pm
by ArneOrtlinghaus
Finally I could better understand, what is needed for Base64 Encoding or Decoding correctly:
You have to know, what characterset should be inside a Base64 decoded string. The original VO functions DecodeBase64 and EncodeBase64 made a coding to the ANSI character set.
Nowadays often an encoding to UTF8 is made, for example in the email raw text to be independant of a national character set.
So if someone has used the VO functions, he should implement both, ANSI and UTF8.
This is the code to have both conversions:

- Encode
local aBytes as byte[]
aBytes := System.Convert.FromBase64String( cValue )
if lutf8
cRetVal := System.Text.Encoding.UTF8:GetString( aBytes )
else
cRetVal := System.Text.Encoding.GetEncoding(1252):GetString( aBytes )
endif

- Decode
local aBytes as byte[]
if lutf8
aBytes := System.Text.Encoding.UTF8:GetBytes( cValue )
else
aBytes := System.Text.Encoding.GetEncoding(1252):GetBytes( cValue )
endif
c := System.Convert.ToBase64String( aBytes, Base64FormattingOptions.InsertLineBreaks )