3

I am currently working on a custom SAPUI5 app. I would like to make a service call, which expects the Guid in a different format than it is currently available.

An example:

  • Available (base64): QvLAUUzUCZbhAAAAjSS2iA==
  • As it should be (hexadecimal): 42F2C0514CD40996E10000008D24B688

I have not found an online decoder, which could produce the desired result, however, I was able to encode the guid 42F2C0514CD40996E10000008D24B to QvLAUUzUCZbhAAAAjss2iA== with the SAP ABAP standard function module HTTP_BASE64_ENCODE. With the usual online encoders, however, I got a different result.

How can I decode the encoded guid with JavaScript so that it has the desired format?

6
  • 1
    atob("QvLAUUzUCZbhAAAAjSS2iA==").replace(/[^]/g, c => c.charCodeAt(0).toString(16)) Commented May 29, 2019 at 12:42
  • Hi Thomas. Thank you for the answer, this looks already quite good! There is only something wrong with zeros. Your function returns "42f2c0514cd4996e10008d24b688" and it should be "42F2C0514CD40996E10000008D24B688". I marked the missing ones bold. It seems like they get lost... Commented May 29, 2019 at 13:21
  • And could you please tell me something about the meaning of the regex and charCodeAt? Thank you! Commented May 29, 2019 at 13:39
  • 1
    The regex is replacing all characters for its hexadecimal representation. Commented May 29, 2019 at 14:01
  • 1
    Possible duplicate of Decode Base64 to Hexadecimal string with javascript Commented May 30, 2019 at 17:58

1 Answer 1

1

The string is in hexadecimal format you will have to convert it.

First you convert the string to binary (atob > charCodeAt) and then using the toString(16) you get the hex.

I will not post the code, since its already explained Decode Base64 to Hexadecimal string with javascript

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.