Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is base64 encoding always one to one

Is it possible to obtain two identical encoded values for two different inputs to the Base64 encoding algorithm?

Let's use another algorithm for example, a function that replaces underscores with the letter X.

Foo_Bar = FooXBar
FooXBar = FooXBar

Can this sort of thing ever happen with Base64 encoding?

like image 570
Ogen Avatar asked Dec 14 '16 22:12

Ogen


People also ask

Is Base64 encoding always the same?

The short answer is yes, unique binary/hex values will always encode to a unique base64 encoded string.

Is there a limit to Base64 encoding?

Since there are only 26 letters in the English alphabet, a maximum of four binary bytes can be represented with three characters from the alphabet. This is where the '64' in Base64 encoding comes from - it can represent up to 64 different combinations using three out of six possible characters.

Is Base64 consistent?

However, as we realized in practice, base64 decoder implementations are in- consistent across various systems, programming languages and software libraries.

What encoding is Base64?

Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding.


2 Answers

No, it cannot happen. Base64 is a lossless conversion (and it even needs a 33% space more). In math terms, the Base64 function is a bijection.

Note how HTTP basic access authentication use this encoding for the username and the password. Anyone can get the original strings from the encoded one, and for this reason this authentication should be used only under HTTPS.

You can find more details on Base64 also on Wikipedia.

like image 148
manfcas Avatar answered Oct 28 '22 08:10

manfcas


No, base64 is just a way of encoding binary data as printable characters.

Strictly speaking, it's just a number system, like binary (base 2), decimal(base 10), or hexadecimal (base 16). Just as you can convert losslessly between those you can with base 64. In fact, mathematically bases are irrelevant, and are only used for notation and human use, math is equivalent no matter what base you use.

like image 31
puhlen Avatar answered Oct 28 '22 07:10

puhlen