0

I have really struggled to find the javascript equivalents to this C# code.

        string authInfo = userName + ":" + userPassword;
        authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
        return "Basic " + authInfo;

Can any one help with this basic base64 encoding?

NoOne
  • 104
  • 12
  • [`btoa()`](https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/btoa) encodes and [`atob()`](https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/atob) decodes. – 4castle Jul 13 '16 at 19:18
  • 3
    Possible duplicate of [How can you encode a string to Base64 in JavaScript?](http://stackoverflow.com/questions/246801/how-can-you-encode-a-string-to-base64-in-javascript) – Frank Tan Jul 13 '16 at 19:19
  • So you know this part: Encoding.Default.GetBytes(authInfo) is that all within btoa() – NoOne Jul 13 '16 at 19:20
  • 1
    It would just be `authInfo = btoa(authInfo)` – 4castle Jul 13 '16 at 19:25
  • ahh right, okay thank you, needed to know for sure because connecting to this API is not the easiest. – NoOne Jul 14 '16 at 07:28

0 Answers0