I'm completing a college job, and would like to know a topic I did not find in Portuguese on the internet.
What are the benefits of base64 ?
I'm completing a college job, and would like to know a topic I did not find in Portuguese on the internet.
What are the benefits of base64 ?
First, Base64 is not an encryption, but rather an encoding. It is not intended to protect information, much less make it irrecoverable or create another information indistinguishable from something random.
The "advantage" of Base64 is to only enable the transmission of binary data using ASCII characters.
For example, a public key, cryptographic, is quite close to the random one, which indicates that a key could be []byte{0x06, 0xFA, 0x14...}
, if you would just show this key, in ASCII, it would become:
ú
In HEX, however, it would be 06FA14
and in Base64 it would be BvoU
. The same information is only represented differently. TLS certificates, OpenPGP, (...) can be encoded in Base64, just to allow copying more easily. But, note that you should not use the standard decryption functions, as most use table-lookup. BoringSSL and LibSodium, for example, decrypt certificates in constant-time and avoid table-lookup. Remember, again, that Base64 is not intended to protect information, on the contrary, it can still make it more insecure in these obscure cases.
Another good example is the links, have you noticed that on YouTube, in Instagram and in several places, you have a link like ?id=ABCDEFER
, and that it always has a fixed size? Usually it is a Base64, or extremely similar (not grouping by 3 bytes).
The advantage here is that the client always receives a% of fixed size% (11 characters, since uint64 has 8 bytes) and the server stores only 8 bytes. If the id
was numeric, the client could have a id
(17 bytes).
And speaking of links, you've noticed that when you want to embed a direct image in an HTML you use ?id=18014398509481984
. This is done precisely because <img src="data:image/png;base64, AAAA....>
is a binary data, using the Base64 causes the information represented only in specific characters. That way, if the original image had a mere png
, it would be represented as []byte{..., 0x22, ...}
in ASCII, which would break the HTML tag. But with Base64 the same%% will be represented differently.