๐๐ฎ๐๐ฒ๐ฒ๐ฐ ๐๐ป๐ฐ๐ผ๐ฑ๐ถ๐ป๐ด ๐๐ ๐ฝ๐น๐ฎ๐ถ๐ป๐ฒ๐ฑ
Base64 is everywhere. You see it in CSS and JWT tokens. Many developers use it without knowing how it works.
Base64 turns binary data into a text string. It uses 64 characters. These include A-Z, a-z, 0-9, plus (+), and slash (/). It uses the equal sign (=) for padding.
Base64 is not encryption. It makes binary data safe for text channels.
How it works:
- Split binary data into 3-byte groups.
- Divide these into four 6-bit chunks.
- Map each chunk to a Base64 character.
Example: The word Man becomes TWFu.
You use Base64 for:
- Email attachments.
- Embedding images in HTML.
- JWT tokens.
- Sending binary data over JSON.
- Basic HTTP authentication.
Javascript supports this natively. Use btoa to encode. Use atob to decode.
Node.js uses data.toString('base64') for files.
Some systems use Base64url. This version is safe for URLs. It replaces plus with minus and slash with underscore. It removes the padding.
Remember these points:
- Base64 is encoding. It is not security.
- The output is 33 percent larger.
- Use it to send binary data through text channels.
- Use Base64url for URLs.
Source: https://dev.to/moksh/base64-encoding-explained-a-practical-guide-for-developers-49hh