Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

url-Encode vs Base64 encoding ( usages)?

I was wondering...

(except the issue with the base64's plus'+' sign in query string - which is translated to 'space' and can be solved by %2b) :---> which is the preferred way to transfer data in query string?

Both functions can be used through the JS commands:

  • btoa
  • encodeUriComponent

so im asking myself(and you) :

when should I use what ? ( ive always used encodeUriCompoonent - by instinct).

the problem that the definitions are different - but the implementations can be similar...

edit

I think ive found the reason for asking.... ( and why nobody asked it before)

enter image description here

like image 404
Royi Namir Avatar asked Apr 22 '12 11:04

Royi Namir


People also ask

Is URL encoding the same as Base64?

The URL encoding is the same as Basic encoding the only difference is that it encodes or decodes the URL and Filename safe Base64 alphabet and does not add any line separation.

What is Base64 encoding used for?

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media that are designed to deal with ASCII. This is to ensure that the data remain intact without modification during transport.

What is Base64 URL encoding?

Base64 is a group of binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. By consisting only of ASCII characters, base64 strings are generally url-safe, and that's why they can be used to encode data in Data URLs.

What is the use of encode URL?

URL Encoding (Percent Encoding) URL encoding converts characters into a format that can be transmitted over the Internet. URLs can only be sent over the Internet using the ASCII character-set. Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format.


1 Answers

base64 is used to transfer binary data. (not supported in IE, cant encode spacial chars.)

encodeURIComponent only encodes special characters.

An interesting thing is that you can't apply base64 to unicode strings without encodeURIComponent: https://developer.mozilla.org/en/DOM/window.btoa

like image 82
meze Avatar answered Sep 26 '22 18:09

meze