Regarding encoding in outsystems

Hi,

Can someone help me with encoding??

We have a requirement where we have to do "urlsafeencoding64 "and "urlsafedecoding64" for the strings

I have used BinarytoBase64 from BinaryData component and whenever it is generating the string it is encoding but there is a problem in that ,we are replicating the stuff from a Ruby file so whenever we encode it from Ruby file it is always different from the one that is generating in the Outsystems web.

Please someone help whether i need to use the BinarytoBase64 component or is it something else.


The below is the source code from Ruby. I am doing all replacing and trimming but final encoded string is different from Ruby to what I am getting from Outsystems



The below one is the reference for Outsystems


So, what's the Ruby code doing functionally, and why is this necessary? What's "safe" about it?

  • It seems when encoding it removes all instances of whitespace followed by "=" - but an encoded Base64 string shouldn't contain any spaces?
  • Next it replaces all "+"s by "-"s, and all "/"s by "_"s, again, why?
  • When decoding, it reverses the previous, so replacing all "-" by "+" and "_" by "/" (so it's in the "orginal" state again).

In your OutSystems code, you remove "="s. That's not what the Ruby code does, nor is it reversible. So you're OS code is botched. And I don't see you replacing "+"s and "/"s (but again, why would anyone want that???).

Lessons to be learned: 1) always make sure you know why something happens functionally and 2) always make sure what's going on technically (it seems you failed at both).

Kilian Hekhuis wrote:

So, what's the Ruby code doing functionally, and why is this necessary? What's "safe" about it?

  • It seems when encoding it removes all instances of whitespace followed by "=" - but an encoded Base64 string shouldn't contain any spaces?
  • Next it replaces all "+"s by "-"s, and all "/"s by "_"s, again, why?
  • When decoding, it reverses the previous, so replacing all "-" by "+" and "_" by "/" (so it's in the "orginal" state again).

In your OutSystems code, you remove "="s. That's not what the Ruby code does, nor is it reversible. So you're OS code is botched. And I don't see you replacing "+"s and "/"s (but again, why would anyone want that???).

Lessons to be learned: 1) always make sure you know why something happens functionally and 2) always make sure what's going on technically (it seems you failed at both).

The below screenshot is for the reference only on how i am using BinarytoBase64 not for how i have replicated the same thing that is there in Ruby??

for your queries i have done all testing from my end in Ruby online editor it doesnt have any whitespace like you mentioned so you can ignore all those gsub() and tr() stuff.


My only question is whenever i use BinarytoBase64  component it is returning an encoded string which is different from Base64.encoding() in Ruby....why this is different...this is my main question ..ignore all those extra stuff that is happening in Ruby code....main encoding strings are different..that is my question.


I don't know what kind of base64 encoding Ruby is applying, but I did find that online tooling (like this one), give the same result as OutSystems. Otherwise, the binary input itself must be different.

Also, you said "I am doing all replacing and trimming", so that's why I was explicitly asking for that, if your only questions is about the bare base64 encoding, perhaps you shouldn't write and show so much that has nothing to do with it.