0

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?

1 Answer 1

2

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.)

1
  • Ah copy and paste errors are the worst... I suppose had I actually decoded them I would have seen that. Thanks pointing that out. Oct 26, 2018 at 18:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .