1

I am sending some parameters in query string by converting them in base64 using method btoa(). I just want to know, do I still need to wrap the result into the encodeURI method to pass on the correct information to the server in URL.

For example:

  • http://example.com/{name} - For this, which one is correct from below?
  • "http://example.com/" + btoa("some-name")
  • "http://example.com/" + encodeURI(btoa("some-name"))
Ankush Jain
  • 5,654
  • 4
  • 32
  • 57

1 Answers1

0

You only need to transform your string to Base 64. See this SO answer for C#:

  var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
  return System.Convert.ToBase64String(plainTextBytes);

You can also read the reason why we use Base 64.

No need to use a method such as encodeURI after, it would be useless because all the characters for Base 64 (A-Z, a-z, 0-9, =, +) are not escaped:

encodeURI escapes all characters except:

A-Z a-z 0-9 ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #

By the way, encodeURI and btoa are about JavaScript, not asp.net as you mention in tags.

Guillaume S.
  • 1,515
  • 1
  • 8
  • 21