Decoded value of base64 string when re-encoded(to base64) gives different output

Sahad Nk

I'm really confused about something here. When I decode the following base64 string

RgRaIY6KP0EIASwW7bCCVSJXCGJsYWhibGFoWAQAAAAASB1UcmFuc2FjdGlvbmFsOiBQYXNzd29yZCBSZXNldEIKAASKCT9YVegBjVITZXhhbXBsZTAxQGdtYWlsLmNvbQlRBAAAAABE6mh0dHBzOi8vd3d3LmV4YW1wbGUxLmNvbS9wYXNzd29yZC1yZXNldD9pZD02MkZZUFcmaGFzaD0yYmI0OTIwODBmMjJjNTZnNmNhYzAzNDlmNDNmNmRiYiZ1dG1fY2FtcGFpZ249VHJhbnNhY3Rpb25hbCUzQSUyMFBhc3N3b3JkJTIwUmVzZXQmdXRtX3NvdXJjZT1TcGFya1Bvc3QmdXRtX21lZGl1bT1lbWFpbCZ1dG1fdGVybT1UcmFuc2FjdGlvbmFsJTNBJTIwUGFzc3dvcmQlMjBSZXNldCZyZWZlcmVyPTYyRllQV0dReyJlbWFpbF91dWlkIjoiMTQ4MDUyNDU3ODQxMS4yODgyMDc0MDY3Nzc4OTUyODk5NTUzOTkiLCJiaW5kaW5nIjoibm90aWZpY2F0aW9ucyJ9

The output is:

FZ!?A,�U"WwwwwwwwwXHTransactional: Aaaaaaaa Gggggg ?XU恍[email protected] QD駴tps://www.abcdefgh.com/endpoint--name?id=62FYPW&valu=2ffg92080f22c50c6grsd349frtyuio9&utm_campaign=Transactional%3A%20Password%20Reset&utm_source=SparkPost&utm_medium=email&utm_term=Transactional%3A%20Pppp%20Mainn&referer=62FYPWGQ{"email_user":"14785243699632.288207406700815289974144","binding":"notifications"}

But when I try to encode the same output value back to base64 it gives me:

RgRaIY4/QQgBLBb9VSJXCHd3d3d3d3d3WARIHVRyYW5zYWN0aW9uYWw6IEFhYWFhYWFhIEdnZ2dnZwoEij9YVU1SE2V4YW1wbGUwMUBnbWFpbC5jb20JUQRE9HRwczovL3d3dy5hYmNkZWZnaC5jb20vZW5kcG9pbnQtLW5hbWU/aWQ9NjJGWVBXJnZhbHU9MmZmZzkyMDgwZjIyYzUwYzZncnNkMzQ5ZnJ0eXVpbzkmdXRtX2NhbXBhaWduPVRyYW5zYWN0aW9uYWwlM0ElMjBQYXNzd29yZCUyMFJlc2V0JnV0bV9zb3VyY2U9U3BhcmtQb3N0JnV0bV9tZWRpdW09ZW1haWwmdXRtX3Rlcm09VHJhbnNhY3Rpb25hbCUzQSUyMFBwcHAlMjBNYWlubiZyZWZlcmVyPTYyRllQV0dReyJlbWFpbF91c2VyIjoiMTQ3ODUyNDM2OTk2MzIuMjg4MjA3NDA2NzAwODE1Mjg5OTc0MTQ0IiwiYmluZGluZyI6Im5vdGlmaWNhdGlvbnMifQ==

What's happening here?

If decode(base64_A) is giving me x, and encode(x) gives me base64_B, how can I generate base64_A from x or base64_B?

Remy Lebeau

The decoded text you have shown contains non-ASCII characters in it. Base64 encodes binary data only, so you have to take character encodings into account when encoding/decoding text.

When encoding base64, a character string has to be charset-encoded to bytes first, such as with UTF-8, and then those bytes can be encoded with base64.

When decoding base64, the result is bytes, which can then be charset-decoded to a character string.

If you use the wrong charset, you will get incorrect results.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Java: Different results when decoding base64 string with java.util.Base64 vs android.util.Base64

From Dev

Why encode string with base64 if it can be easily decoded

From Dev

foreach a decoded Base64 string after use $_GET

From Dev

Different output between Powershell ToBase64String & Linux base64

From Dev

gzip string, then base64 value of gzip

From Dev

Validate a base64 decoded image in laravel

From Dev

Different output after decode and encode data (base64)

From Dev

Convert Base64 String to Byte Value String in Java

From Dev

Same BASE64 encoded String for different byte arrays

From Dev

Length of the string is different after converting from base64

From Dev

Different Base64 String of same image in JS and Java

From Java

Mismatch data when using different Base64 libraries

From Dev

Mismatch data when using different Base64 libraries

From Dev

different results when I encode a character to base64

From Dev

base64 'payload' string from rabbitmq queue can't be decoded properly

From Dev

base64 'payload' string from rabbitmq queue can't be decoded properly

From Dev

Strange IOError when opening base64 string in PIL

From Dev

check if string is base64

From Dev

Validate Base64 string

From Dev

Extract Base64 String

From Dev

Decoding Base64 string

From Dev

Base64 encode gives different result on linux CentOS terminal and in Java

From Dev

Java 8 - Base64 encoding generates "==" which can not be decoded

From Dev

searching base64 decoded binary data for text in Python

From Dev

Getting Byte[] from Decoded base64 MIME Part

From Dev

bash base64 producing inconsistent output?

From Dev

Why is there an inconsistency in base64 output?

From Dev

image base64, and optimase output

From Dev

Decode a base64 string to a decimal string

Related Related

  1. 1

    Java: Different results when decoding base64 string with java.util.Base64 vs android.util.Base64

  2. 2

    Why encode string with base64 if it can be easily decoded

  3. 3

    foreach a decoded Base64 string after use $_GET

  4. 4

    Different output between Powershell ToBase64String & Linux base64

  5. 5

    gzip string, then base64 value of gzip

  6. 6

    Validate a base64 decoded image in laravel

  7. 7

    Different output after decode and encode data (base64)

  8. 8

    Convert Base64 String to Byte Value String in Java

  9. 9

    Same BASE64 encoded String for different byte arrays

  10. 10

    Length of the string is different after converting from base64

  11. 11

    Different Base64 String of same image in JS and Java

  12. 12

    Mismatch data when using different Base64 libraries

  13. 13

    Mismatch data when using different Base64 libraries

  14. 14

    different results when I encode a character to base64

  15. 15

    base64 'payload' string from rabbitmq queue can't be decoded properly

  16. 16

    base64 'payload' string from rabbitmq queue can't be decoded properly

  17. 17

    Strange IOError when opening base64 string in PIL

  18. 18

    check if string is base64

  19. 19

    Validate Base64 string

  20. 20

    Extract Base64 String

  21. 21

    Decoding Base64 string

  22. 22

    Base64 encode gives different result on linux CentOS terminal and in Java

  23. 23

    Java 8 - Base64 encoding generates "==" which can not be decoded

  24. 24

    searching base64 decoded binary data for text in Python

  25. 25

    Getting Byte[] from Decoded base64 MIME Part

  26. 26

    bash base64 producing inconsistent output?

  27. 27

    Why is there an inconsistency in base64 output?

  28. 28

    image base64, and optimase output

  29. 29

    Decode a base64 string to a decimal string

HotTag

Archive