Solved: Using atob/btoa server side, and GlideRhinoHelper? - ServiceNow Community

Using atob/btoa server side, and GlideRhinoHelper?

xiaix
Tera Guru

So, I'm trying to Base64 decode a Base64 encoded string within a Script Include (server side).  Of course I get "atob is not defined", so I'm wondering how to do this in ServiceNow.

I'm thinking I can use ServiceNow's "GlideRhinoHelper", but there is 0 documentation for it!

Anyone able to assist?

1 ACCEPTED SOLUTION

xiaix
Tera Guru

Ok, finally got it.

JSON.parse(GlideStringUtil.base64Decode(s))

find_real_file.png


So for example this Base64 encoded string:
eyJndWlkIjoiMjhmZDdiYmQtM2U2Ny00MDMwLTlhN2YtN2YzMzk1Zjc3Nzg2IiwiYWN0aW9uIjoidXBkYXRlIiwiZmllbGRzIjoiZW1haWwsbGFzdF9uYW1lIn0=

would process out to:

find_real_file.png

View solution in original post

5 REPLIES 5

xiaix
Tera Guru

Nevermind... found it.

GlideStringUtil.base64Decode()

GlideStringUtil.base64Encode()

Well, this sucks... seems you can only use GlideStringUtil.base64Decode() on something that was encoded with GlideBase64.encode()

And it there is no such thing as GlideBase64.decode()

So if something was encoded with btoa('test'), GlideStringUtil.base64Decode() won't work.

So frustrating!

xiaix
Tera Guru

Ok, finally got it.

JSON.parse(GlideStringUtil.base64Decode(s))

find_real_file.png


So for example this Base64 encoded string:
eyJndWlkIjoiMjhmZDdiYmQtM2U2Ny00MDMwLTlhN2YtN2YzMzk1Zjc3Nzg2IiwiYWN0aW9uIjoidXBkYXRlIiwiZmllbGRzIjoiZW1haWwsbGFzdF9uYW1lIn0=

would process out to:

find_real_file.png

Hi xiaix, 

 

Did you have to do anything to else after "GlideStringUtil.base64Decode() on something that was encoded with GlideBase64.encode()" to make GlideStringUtil.base64Decode() work? I'm trying to convert a base64 string (generated using CertificateEncryption.generateMac() ) into hex and GlideStringUtil.base64Decode() doesn't work.