I'm writing a client-side code in JS , which should be compatible with a third-party c# service which I cannot modify at all.
The service supplies a base64 unicode encoded string (a JSON), for the sake of the (simplified) example this is the c# code:
var myString = Encoding.Unicode.GetBytes("{\"counter\":0}");
var encodedString = Convert.ToBase64String(myString);
which results in : "ewAiAGMAbwB1AG4AdABlAHIAIgA6ADAAfQA="
now I need to update this encoded JSON at the client-side, and return a valid base64 string which will be decoded by this C# code:
byte[] bytes = Convert.FromBase64String(encodedString);
string decodedString = Encoding.Unicode.GetString(bytes);
All the solutions/examples I've found online resulted in the decoding functions to output a invalid result.
for example, when using the basic window.btoa("{\"counter\":1}")
resulted in eyJjb3VudGVyIjoxfQ==
which in turn , when decoding on the c# app, will be cause a format exception at best, or result in total gibberish.
any Ideas?