title: encode base 64 in javascript, decode unicode in c#
body: <p>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.</p>
  
  <p>The service supplies a base64 <strong>unicode</strong> encoded string (a JSON), 
  for the sake of the (simplified) example this is the c# code:</p>
  
  <pre><code>var myString = Encoding.Unicode.GetBytes("{\"counter\":0}");
  var encodedString = Convert.ToBase64String(myString);
  </code></pre>
  
  <p>which results in : "ewAiAGMAbwB1AG4AdABlAHIAIgA6ADAAfQA="</p>
  
  <p>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:</p>
  
  <pre><code>byte[] bytes = Convert.FromBase64String(encodedString);
  string decodedString = Encoding.Unicode.GetString(bytes);
  </code></pre>
  
  <p>All the solutions/examples I've found online resulted in the decoding functions to output a invalid result.
  for example, when using the basic <code>window.btoa("{\"counter\":1}")</code> resulted in <code>eyJjb3VudGVyIjoxfQ==</code>
  which in turn , when decoding on the c# app, will be cause a format exception at best, or result in total gibberish.</p>
  
  <p>any Ideas?</p>