0

I want to decode a string. When I do it on PHP, Go, Python it gives different result than NodeJS. I tried a lot of base64 encoding/decoding libraries but result is always same. I spent 5 hours on this bug.

I want to decode this:

5wEoKBapCmDCaJrRCiwKFK1SIOQ8Y1K2V5UZbAOuNOhVgY+MEhQKBXVhdG9tEgsyMDA5OTAwMDAwMBIsChT59Ec6oQnuK5uLa1iNNvuWKdSOMBIUCgV1YXRvbRILMjAwOTkwMDAwMDASEwoNCgV1YXRvbRIEMTAwMBDAmgwaagom61rphyEDEfz4OLFOxWBL6HQbJLlw1nRE7zbfrXzYFJg8YIKC5fwSQAYqnpgwKpdJMx6L5ktYPYb7Lm81Xe2eXoRAloQQNKyhTvHaOBZzWGYSQSuWlMPxhJ9C4sxbeg1UN2lVJ8NLrYo=

When I decode it with Node result is:

�((�
`�h��
,
�R �<cR�W�l�4�U���
uatom
     20099000000,
��G:�   �+��kX�6��)Ԏ0
uatom
     20099000000

uatom1000��
           j
T7iU'�K��N�`K�t�p�tD�6߭|��<`����@*��0*�I3��KX=��.o5]�^�@��4��N��8sXfA+����B��[z

On the other languages like PHP, Python, Go result is:

?((?
`?h??
,
?R ?<cR?W?l?4?U???
uatom
     20099000000,
??G:?  ?+??kX?6??)Ԏ0
uatom
     20099000000

uatom1000??
           j
T7iU'?K??

What I have tried so far? I tried built in Buffer:

Buffer.from("myData", 'base64').toString("utf-8")

I tried this solution: https://stackoverflow.com/a/30106551/7886428 But it gives error:

UnhandledPromiseRejectionWarning: URIError: URI malformed
    at decodeURIComponent (<anonymous>)
haberimyok
  • 13
  • 3
  • Looks like it's decoding the same way in Node but whatever you're using to display the output has a different encoding – Phil Mar 20 '20 at 00:35
  • Have you tried using js-base64 (https://github.com/dankogai/js-base64), specifically the `Base64.atob(encodedStr)` function call? I tried it and while it is not the same as what your printing, it doesn't contain the � characters... – Daniel Bank Mar 20 '20 at 03:53
  • Phil I use macos terminal for both of the result. @DanielBank Yes it does not contain � characters but it is wrong. Even length of the result is different from other languages. – haberimyok Mar 20 '20 at 09:34

0 Answers0