different results when I encode a character to base64

남현우

When I encode a character to base64, I get different results depending on the the way I pass the character: For example, I want to encode chr(128) => €

1.passing the result of chr(): base64_encode(chr(128)) => 'gA=='
2.passing the character directly: base64_encode('€') => '4oKs'

Why are the results different?

jps

chr(128) returns a 1 byte character which represents the €-sign, therefore the base64 encoded string encodes ony 1 byte (80 hexacdecimal = 128 decimal):

echo bin2hex(base64_decode('gA=='));

80

On the other hand, in base64_encode('€') the '€' is a unicode string, and the encoded result contains 3 bytes, the unicode representation of the Euro-sign:

echo bin2hex(base64_decode('4oKs'));

E282AC

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

base64 encode is giving ambigious results

From Dev

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

From Dev

Base64 decode encode, getting different data

From Dev

Different output after decode and encode data (base64)

From Dev

Why is base64 using CryptoJS different than a standard base64 encode?

From Dev

Different results when sorting character vectors

From Dev

Different results when sorting character vectors

From Java

How do I encode and decode a base64 string?

From Java

How can I encode a string to Base64 in Swift?

From Dev

Swift 2 base64 Encoding Yield Different Results

From Dev

php base64_encode hash_hmac and java gives different results

From Dev

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

From Dev

base64 encode HttpPostedFileBase

From Dev

Javascript base64 encode

From Java

Mismatch data when using different Base64 libraries

From Dev

Mismatch data when using different Base64 libraries

From Dev

base64 encode binary string returns different values in NodeJS and Python

From Dev

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

From Dev

Vba Excel. Resize image when loaded from file and then encode it base64

From Dev

JS: how can I base64 encode a local file without XMLHttpRequest?

From Dev

How do I get external image and encode it to base64 on client WebApp?

From Dev

I can't write/encode JSON files properly. Code produces different results

From Dev

node.js base64 encoding a string yields slightly different results (local vs heroku)

From Dev

PHP base64_encode adding strange character at the end of string

From Dev

PHP base64_encode returning incorrect results

From Dev

Encode Carrierwave attachment to base64 in Rails

From Dev

Base64 encode file and OutOfMemory error

From Dev

How to encode an image resource to base64?

From Dev

Encode a ImageMagick image with Base64

Related Related

  1. 1

    base64 encode is giving ambigious results

  2. 2

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

  3. 3

    Base64 decode encode, getting different data

  4. 4

    Different output after decode and encode data (base64)

  5. 5

    Why is base64 using CryptoJS different than a standard base64 encode?

  6. 6

    Different results when sorting character vectors

  7. 7

    Different results when sorting character vectors

  8. 8

    How do I encode and decode a base64 string?

  9. 9

    How can I encode a string to Base64 in Swift?

  10. 10

    Swift 2 base64 Encoding Yield Different Results

  11. 11

    php base64_encode hash_hmac and java gives different results

  12. 12

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

  13. 13

    base64 encode HttpPostedFileBase

  14. 14

    Javascript base64 encode

  15. 15

    Mismatch data when using different Base64 libraries

  16. 16

    Mismatch data when using different Base64 libraries

  17. 17

    base64 encode binary string returns different values in NodeJS and Python

  18. 18

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

  19. 19

    Vba Excel. Resize image when loaded from file and then encode it base64

  20. 20

    JS: how can I base64 encode a local file without XMLHttpRequest?

  21. 21

    How do I get external image and encode it to base64 on client WebApp?

  22. 22

    I can't write/encode JSON files properly. Code produces different results

  23. 23

    node.js base64 encoding a string yields slightly different results (local vs heroku)

  24. 24

    PHP base64_encode adding strange character at the end of string

  25. 25

    PHP base64_encode returning incorrect results

  26. 26

    Encode Carrierwave attachment to base64 in Rails

  27. 27

    Base64 encode file and OutOfMemory error

  28. 28

    How to encode an image resource to base64?

  29. 29

    Encode a ImageMagick image with Base64

HotTag

Archive