S
S
Snewer2014-05-12 19:20:21
PHP
Snewer, 2014-05-12 19:20:21

Base64 - what are the equals signs for?

Hello!
Why do you put "=" / "==" at the end of the converted to base64 string? Removing them, the deconversion goes off with a bang. Is it possible to "clean" them? Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2014-05-12
@OLS

Base64 converts in blocks of 3 bytes (creating codes of 4 bytes):
- if the length of the original block was a multiple of 3, then it will be encoded as a whole and there will be no "=" signs
- if the length of the original block had a remainder of 1 from dividing by 3, then it will be encoded in 2 bytes (6 bits + 2 bits), and in order for the final code to be a multiple of 4 in length, "==" will be added at the end
- if the length of the original block had a remainder of 2 from dividing by 3, then it will be encoded into 3 bytes (6 bits + 6 bits + 4 bits), and in order for the final code to be a multiple of 4 in length, "=" will be added at the end.
It is undesirable to discard tails, because. You cannot be sure that the decoding algorithm will accept the last block that is not a multiple of 4.

E
Eugene Obrezkov, 2014-05-12
@ghaiklor

These are suffixes.
Only upper and lower case Latin characters are used - symbols (A-Z, a-z), numbers (0-9), and symbols "+" and "/", with the symbol "=" as a special suffix code.
Can they be cleaned? What for? Save a couple kb?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question