Encryption BASE64

Asked

Viewed 950 times

0

I am concluding a college job, and I would like to know a topic that I did not find in Portuguese on the Internet.

What are the benefits of Base64?

  • 1

    One of the benefits is to remove spaces and special characters, avoiding conflict in other parts of the application where these characters may have a special meaning

  • 1

    See if that’s not what you’re looking for here https://answall.com/questions/53102/para-que-serve-o-encoding-em-base64

  • 1

    Base64 is a way to represent binary data in string, as well as hexadecimal representation is. But as Guilherme cited the characters are chosen to minimize any problem with possible encoding.

  • 4

    Just remember that Base 64 nay is cryptography: https://www.di-mgt.com.au/encode_encrypt.html

1 answer

1

First of all, Base64 is not an encryption, but an encryption of some kind. It is not intended to protect information, much less make it unrecoverable or create other information indistinguishable from something random.


The "advantage" of Base64 is only to enable the transmission of binary data using ASCII characters.

For example, a public key, cryptographic, is quite close to random, which indicates that a key could be []byte{0x06, 0xFA, 0x14...}, if you were simply to show this key, in ASCII, it would become:

ú

Meanwhile in HEX would stay 06FA14 and in Base64 would be BvoU. The same information is only represented in another way. TLS certificates, Openpgp, (...) can be encoded in Base64, precisely to make copying easier. But, note that you should not use the standard decoding functions, since most use table-lookup. Boringssl and Libsodium, for example, decode the certificates on constant-time and avoid the table-lookup. Remember, again, that Base64 is not intended to protect information, on the contrary, can still make more insecure in these obscure cases.


Another good example is the links, already noticed that on Youtube, on Instagram and in several places, has a link like ?id=ABCDEFER, and that always has a fixed size? Usually it is a Base64, or extremely similar (not grouping by 3 bytes).

The advantage in this case is: the customer always receives a id fixed size (11 characters, since uint64 has 8 bytes) and the server stores only 8 bytes. If the id if numerical, the customer could have a ?id=18014398509481984 (17 bytes).

And speaking of links, have you noticed that when you want to embed a direct image in an HTML <img src="data:image/png;base64, AAAA....>. This is done precisely because the png is binary data, using Base64 makes the information represented only in specific characters. That way, if the original image had a mere []byte{..., 0x22, ...}, he would be represented as " in ASCII, which would break the HTML tag. But, with Base64 the same 0x22 will be represented otherwise.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.