简体   繁体   中英

Correct way to pass base64 info in URL as query string?

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"))

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 (AZ, az, 0-9, =, +) are not escaped :

encodeURI escapes all characters except:

 AZ az 0-9 ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM