0

I used to change hexString like 0B81040000001E to C4EEAAAAHg==

I used web site http://tomeko.net/online_tools/hex_to_base64.php

but problem is that I want to implement this change process in my angular app

many people says I should use btoa(0B81040000001E) to change hexstring to base64. but when I tried, result came to different like "MEI4MTA0MDAwMDAwMUU=" Not "C4EEAAAAHg=="

did I use something wrong? value "C4EEAAAAHg==" is the one that I think I should get.

C4EEAAAAHg== is not base 64 that I know?

How can I change hexstring data to base 64...?

  • [MDN](https://developer.mozilla.org/fr/docs/D%C3%A9coder_encoder_en_base64) explains that in details. Have you taken a look at it ? –  Nov 08 '18 at 15:13
  • 1
    Possible duplicate of [HEX to Base64 converter for JavaScript](https://stackoverflow.com/questions/23190056/hex-to-base64-converter-for-javascript) – Basel Issmail Nov 08 '18 at 15:24

1 Answers1

3

here is how you can transform a HexString to Base64 :

let base64String = btoa("0B81040000001E".match(/\w{2}/g).map(a => {return String.fromCharCode(parseInt(a, 16));} ).join(""))

regards,

Mohamed Ali RACHID
  • 3,245
  • 11
  • 22