0

I try to encode a string in both browser and server but I have different base64 encoding for a specific string

Here is my string: "£aº©S=³hPó c¨¸" (Hexa: 00a3006100ba00a900940053003d00b30068005000f300900020006300a800b8 )

Client-side: I encode this String using btoa() and I have : o2G6qZRTPbNoUPOQIGOouA== and this is the result I expect.

Server-side: I code this String using Buffer according to this answer in Node.js i have :

var ciphertext = ... // myString
console.log(ciphertext.hexEncode()); // 00a3006100ba00a900940053003d00b30068005000f300900020006300a800b8  
console.log(Buffer.from(ciphertext, 'utf8').toString('base64')) // wqNhwrrCqcKUUz3Cs2hQw7PCkCBjwqjCuA==
console.log(Buffer.from(ciphertext, 'ucs2').toString('base64')) // owBhALoAqQCUAFMAPQCzAGgAUADzAJAAIABjAKgAuAA=
Community
  • 1
  • 1
Zycho
  • 298
  • 3
  • 13

1 Answers1

0

I managed to obtain the base64 encoding I expect using the node-package base-64

I still don't know why, so if someone has a clue

var base64 = require('base-64');

var ciphertext = ...; //myString
var encoded = base64.encode(bytes);
console.log(encoded); // o2G6qZRTPbNoUPOQIGOouA==
Zycho
  • 298
  • 3
  • 13