0

I have string like below

b/dWBWBYDdE2A5Uh

I want to convert to:

Uint8Array(12) [111, 247, 86, 5, 96, 88, 13, 209, 54, 3, 149, 33, buffer: ArrayBuffer(12), byteLength: 12, byteOffset: 0, length: 12, Symbol(Symbol.toStringTag): 'Uint8Array']

So I tried something like below

new TextEncoder("utf-8").encode("b/dWBWBYDdE2A5Uh");

But I get

Uint8Array(16) [98, 47, 100, 87, 66, 87, 66, 89, 68, 100, 69, 50, 65, 53, 85, 104, buffer: ArrayBuffer(16), byteLength: 16, byteOffset: 0, length: 16, Symbol(Symbol.toStringTag): 'Uint8Array'] ,

I believe this string is encrypted. This was done by third party website, so I am trying to decode it.

halfer
  • 19,824
  • 17
  • 99
  • 186
Gracie williams
  • 1,287
  • 2
  • 16
  • 39

1 Answers1

1

Looks like b/dWBWBYDdE2A5Uh is the base-64 encoded version of the given 12 bytes of binary data. You can decode base-64 with atob, but it gives you a string and not an Uint8Array. Each character in the string represents one byte.

There is no built-in function to convert this string to an Uint8Array, but we can do it, as adapted from this answer:

>> Uint8Array.from(atob('b/dWBWBYDdE2A5Uh'), c => c.charCodeAt(0))
Uint8Array(12) [ 111, 247, 86, 5, 96, 88, 13, 209, 54, 3, … ]
Thomas
  • 174,939
  • 50
  • 355
  • 478