1
0
-1

Hello,


if I use BASE64 encode text for webservise purposes, CRLF are lost (after decoding) (sad) 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 )



    CommentAdd your comment...

    8 answers

    1.  
      2
      1
      0

      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)

        CommentAdd your comment...
      1.  
        1
        0
        -1

        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.

          CommentAdd your comment...
        1.  
          1
          0
          -1

          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.

            CommentAdd your comment...
          1.  
            1
            0
            -1

            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.

              CommentAdd your comment...
            1.  
              1
              0
              -1

              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=



                CommentAdd your comment...
              1.  
                1
                0
                -1

                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.

                  CommentAdd your comment...
                1.  
                  1
                  0
                  -1

                  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?


                    CommentAdd your comment...
                  1.  
                    1
                    0
                    -1

                    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)
                      CommentAdd your comment...