Skip to main content

SOLVED Base64 after encoding/decoding CRLF lost and 3rd side WebService consumers

  • January 28, 2019
  • 8 replies
  • 0 views

Hello,


if I use BASE64 encode text for webservise purposes, CRLF are lost (after decoding) 😔 Any hints ? It is OS dependend?  Many thanks

Petr V

 

variables
   string lc_data
endvariables
 
lc_data  = $encode( "BASE64", EDITBOX )
EDITBOX = $decode( "BASE64", lc_data )



8 replies

Forum|alt.badge.img

Hello,


if I use BASE64 encode text for webservise purposes, CRLF are lost (after decoding) 😔 Any hints ? It is OS dependend?  Many thanks

Petr V

 

variables
   string lc_data
endvariables
 
lc_data  = $encode( "BASE64", EDITBOX )
EDITBOX = $decode( "BASE64", lc_data )



Hi Petr, 


When the data is decoded is returned as Raw, to convert the data from Raw to String use this:

vRawData = $decode("BASE64", lc_data)
EDITBOX = $encode("USTRING", vRawData)

  • Author
  • New Participant
  • January 29, 2019

Hello,


if I use BASE64 encode text for webservise purposes, CRLF are lost (after decoding) 😔 Any hints ? It is OS dependend?  Many thanks

Petr V

 

variables
   string lc_data
endvariables
 
lc_data  = $encode( "BASE64", EDITBOX )
EDITBOX = $decode( "BASE64", lc_data )



Thanks for aswer,


so to decoding I need "USTRING", so will other NON-uniface side (consumer of these BASE64 coded data send in element via webservice) be able to decode these raw data?



Roger Wallin
Forum|alt.badge.img
  • Participating Frequently
  • January 29, 2019

Hello,


if I use BASE64 encode text for webservise purposes, CRLF are lost (after decoding) 😔 Any hints ? It is OS dependend?  Many thanks

Petr V

 

variables
   string lc_data
endvariables
 
lc_data  = $encode( "BASE64", EDITBOX )
EDITBOX = $decode( "BASE64", lc_data )



Hi Petr,

Yes to be sure that it works the same for Uniface and other clients, it's convenient to use base64 as the outermost "encryption". Not having that you will in some cases get some truncated data in Uniface.

Regards RogerW.


  • Author
  • New Participant
  • January 29, 2019

Hello,


if I use BASE64 encode text for webservise purposes, CRLF are lost (after decoding) 😔 Any hints ? It is OS dependend?  Many thanks

Petr V

 

variables
   string lc_data
endvariables
 
lc_data  = $encode( "BASE64", EDITBOX )
EDITBOX = $decode( "BASE64", lc_data )



to demonstrate where problem is:


I want to encode this :

a

b

c

with uniface $encode BASE64 I get :

YQ1iDWM=

If I try https://www.base64encode.net/ I get :

YQ0KYg0KYw==

At the first sight there is difference with CRLF...

So is there way I can get same output with uniface as well?
It seems that some 3rd sides are unable to decode "short" uniface encoded version YQ1iDWM=




Roger Wallin
Forum|alt.badge.img
  • Participating Frequently
  • January 29, 2019

Hello,


if I use BASE64 encode text for webservise purposes, CRLF are lost (after decoding) 😔 Any hints ? It is OS dependend?  Many thanks

Petr V

 

variables
   string lc_data
endvariables
 
lc_data  = $encode( "BASE64", EDITBOX )
EDITBOX = $decode( "BASE64", lc_data )



Actually in eg. C# they will probably do almost the same (in two steps) 

byte[] rawMyData = System.Convert.FromBase64String(b64MyData);
string vMyDataEdit = Encoding.UTF8.GetString(rawMyData);

or something like this

byte[] rawMyData = System.Convert.FromBase64String(b64MyData);
string vMyDataEdit = objARijndael.DecryptStringFromBytes(rawMyData);

where DecryptStringFromBytes-function knows what to do with the byte-array.


Regards RogerW.


Roger Wallin
Forum|alt.badge.img
  • Participating Frequently
  • January 29, 2019

Hello,


if I use BASE64 encode text for webservise purposes, CRLF are lost (after decoding) 😔 Any hints ? It is OS dependend?  Many thanks

Petr V

 

variables
   string lc_data
endvariables
 
lc_data  = $encode( "BASE64", EDITBOX )
EDITBOX = $decode( "BASE64", lc_data )



That way, you should probably encode it to raw before you encode it to base64. I usually encode it by some hash function (eg. SHA1) or encryption algorithm before encoding to Base64.

But perhaps like this, 

tRaw = $encode("URAW", myData)
tBase64 = $encode("BASE64", tRaw)

Regards RogerW.


  • Author
  • New Participant
  • January 29, 2019

Hello,


if I use BASE64 encode text for webservise purposes, CRLF are lost (after decoding) 😔 Any hints ? It is OS dependend?  Many thanks

Petr V

 

variables
   string lc_data
endvariables
 
lc_data  = $encode( "BASE64", EDITBOX )
EDITBOX = $decode( "BASE64", lc_data )



SOLUTION : OUTPUT depends on end-of-line used, see example below


You want encode this :

a

b

c


variables    
  string crlf, xdata 
endvariables

; to get YQ1iDWM=

crlf = "%%^"

 

; to get YQ0KYg0KYw==

crlf = $concat($string("
"), $string("
"))


xdata = $concat( "a", crlf, "b", crlf, "c" ) 
EDITBOX = $encode("BASE64", xdata)


Roger Wallin
Forum|alt.badge.img
  • Participating Frequently
  • January 30, 2019

Hello,


if I use BASE64 encode text for webservise purposes, CRLF are lost (after decoding) 😔 Any hints ? It is OS dependend?  Many thanks

Petr V

 

variables
   string lc_data
endvariables
 
lc_data  = $encode( "BASE64", EDITBOX )
EDITBOX = $decode( "BASE64", lc_data )



Nice that you found a solution, and yes it's often a problem with CR+LF or only LF.

I think that Alejandro and I try to pinpoint that you should go via raw-data, which apparently is the same as a byte-array in many other languages.

Then your encoding is the same as encoding/decoding images and other binary data. And somehow the Uniface behaviour of returning raw data here  
vRawData = $decode("BASE64", lc_data)

forces you to go via raw data in most cases. Anyone knowing more about BASE64 encode and decode, raw vs string etc.?

Regards RogerW.