-3

I need help to try make this piece of code in javascript. In c# is very simple however I don't know how I can do it in javascript.

Any help? Thank you

string user = txtUser.Text;
byte[] userBytes = UTF8Encoding.UTF8.GetBytes(user);
user = Convert.ToBase64String(userBytes, Base64FormattingOptions.None);
user3178157
  • 61
  • 1
  • 10
  • 1
    https://stackoverflow.com/questions/30106476/using-javascripts-atob-to-decode-base64-doesnt-properly-decode-utf-8-strings – Dave Anders Apr 11 '18 at 09:57
  • 1
    Take a look at the "btoa" function – baileyrt Apr 11 '18 at 09:57
  • Possible duplicate of [Using Javascript's atob to decode base64 doesn't properly decode utf-8 strings](https://stackoverflow.com/questions/30106476/using-javascripts-atob-to-decode-base64-doesnt-properly-decode-utf-8-strings) – H77 Apr 11 '18 at 09:58

1 Answers1

0

You can use btoa() function in JavaScript to achieve the same functionality as C# code you mentioned as shown below

var user = document.getElementById("txtUser").value;
user = btoa(user);
Muhammad Faizan
  • 1,709
  • 1
  • 15
  • 37
UTS
  • 1