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

Jeremy Ragsdale

I have done some searching and I gather that the issue may be down to a new line character that is being handled different locally vs on heroku but I am not sure where or how to deal with that.

I have a pretty basic app that needs to base64 encode a string.

The code is pretty basic node code

let buff = new Buffer(cics);  
let base64data = buff.toString('base64');

Here are the results, they are similar, only different by the "YQ=="

Local
    MzQ0YzAxOWMtMWZhMC00ODU0LTlhMjMtOWNiNmYzYTdmMzNkOjlhZThhMWUwLTg2OWItNDg2Yi1iNzFkLWRkMGM1NGQ3NWFhYQ==

Heroku
    MzQ0YzAxOWMtMWZhMC00ODU0LTlhMjMtOWNiNmYzYTdmMzNkOjlhZThhMWUwLTg2OWItNDg2Yi1iNzFkLWRkMGM1NGQ3NWFh

Anyone know what could be going on here?

user1686

Well, decode them and take a look.

$ echo 'MzQ0YzAxOWMtMWZhMC00ODU0LTlhMjMtOWNiNmYzYTdmMzNkOjlhZThhMWUwLTg2OWItNDg2Yi1iNzFkLWRkMGM1NGQ3NWFhYQ==' | base64 -d | hexdump -C
00000000  33 34 34 63 30 31 39 63  2d 31 66 61 30 2d 34 38  |344c019c-1fa0-48|
00000010  35 34 2d 39 61 32 33 2d  39 63 62 36 66 33 61 37  |54-9a23-9cb6f3a7|
00000020  66 33 33 64 3a 39 61 65  38 61 31 65 30 2d 38 36  |f33d:9ae8a1e0-86|
00000030  39 62 2d 34 38 36 62 2d  62 37 31 64 2d 64 64 30  |9b-486b-b71d-dd0|
00000040  63 35 34 64 37 35 61 61  61                       |c54d75aaa|
00000049
$ echo 'MzQ0YzAxOWMtMWZhMC00ODU0LTlhMjMtOWNiNmYzYTdmMzNkOjlhZThhMWUwLTg2OWItNDg2Yi1iNzFkLWRkMGM1NGQ3NWFh' | base64 -d | hexdump -C
00000000  33 34 34 63 30 31 39 63  2d 31 66 61 30 2d 34 38  |344c019c-1fa0-48|
00000010  35 34 2d 39 61 32 33 2d  39 63 62 36 66 33 61 37  |54-9a23-9cb6f3a7|
00000020  66 33 33 64 3a 39 61 65  38 61 31 65 30 2d 38 36  |f33d:9ae8a1e0-86|
00000030  39 62 2d 34 38 36 62 2d  62 37 31 64 2d 64 64 30  |9b-486b-b71d-dd0|
00000040  63 35 34 64 37 35 61 61                           |c54d75aa|
00000048

Notice that Heroku is encoding a buffer that's one byte shorter (missing the final letter a) – or its Base64 encoder is buggy and discards incomplete chunks instead of correctly using padding.

(As a shortcut, because Base64 output always consists of 4-character chunks, you can decode just the YQ== on its own. It indeed decodes to the letter a.)

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 encoding of String in Node.js

From Dev

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

From Dev

Swift 2 base64 Encoding Yield Different Results

From Dev

Android encoding PNG to base64 string producing invalid results

From Dev

Base64 String Encoding C# vs TSQL

From Java

How to do Base64 encoding in node.js?

From Dev

URL Encoding yields two different results? Only one works

From Dev

Filter "base query" for slightly different results

From Java

String based data encoding: Base64 vs Base64url

From Dev

Arithmetic calculation using Linq.Expressions yields different results on 32 vs 64bit

From Dev

Computing hash in PHP yields different results on local and test environments.

From Dev

Different Base64 String of same image in JS and Java

From Dev

Decode Base64 string in node.js

From Dev

node js base64 string into utf8 issue

From Dev

How to compute an SHA256 hash and Base64 String encoding in JavaScript/Node

From Dev

Convert buffer base64 -> utf8 encoding node.js

From Dev

Base64 encoding of String in Qt 5

From Dev

Base64 Encoding difference in a particular String

From Dev

Node JS Detect string encoding

From Dev

Node JS Detect string encoding

From Dev

Python Base64 encoding Vs Java Base64 encoding

From Dev

Comparing values yields different results

From Dev

Makefile variable yields different results

From Dev

Different base64 encoding between python versions

From Dev

Node.js Hmac SHA256 base64 of string

From Dev

How to check if a string is plaintext or base64 format in Node.js

From Dev

Applying str() explicitly vs allowing Django to do it itself yields different results in templates

From Dev

"subset" and "[" on dataframe give slightly different results, why?

From Dev

Base64 encoding or bin2hex random string

Related Related

  1. 1

    Base64 encoding of String in Node.js

  2. 2

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

  3. 3

    Swift 2 base64 Encoding Yield Different Results

  4. 4

    Android encoding PNG to base64 string producing invalid results

  5. 5

    Base64 String Encoding C# vs TSQL

  6. 6

    How to do Base64 encoding in node.js?

  7. 7

    URL Encoding yields two different results? Only one works

  8. 8

    Filter "base query" for slightly different results

  9. 9

    String based data encoding: Base64 vs Base64url

  10. 10

    Arithmetic calculation using Linq.Expressions yields different results on 32 vs 64bit

  11. 11

    Computing hash in PHP yields different results on local and test environments.

  12. 12

    Different Base64 String of same image in JS and Java

  13. 13

    Decode Base64 string in node.js

  14. 14

    node js base64 string into utf8 issue

  15. 15

    How to compute an SHA256 hash and Base64 String encoding in JavaScript/Node

  16. 16

    Convert buffer base64 -> utf8 encoding node.js

  17. 17

    Base64 encoding of String in Qt 5

  18. 18

    Base64 Encoding difference in a particular String

  19. 19

    Node JS Detect string encoding

  20. 20

    Node JS Detect string encoding

  21. 21

    Python Base64 encoding Vs Java Base64 encoding

  22. 22

    Comparing values yields different results

  23. 23

    Makefile variable yields different results

  24. 24

    Different base64 encoding between python versions

  25. 25

    Node.js Hmac SHA256 base64 of string

  26. 26

    How to check if a string is plaintext or base64 format in Node.js

  27. 27

    Applying str() explicitly vs allowing Django to do it itself yields different results in templates

  28. 28

    "subset" and "[" on dataframe give slightly different results, why?

  29. 29

    Base64 encoding or bin2hex random string

HotTag

Archive