๐๐ฎ๐๐ฒ๐ฒ๐ฐ ๐๐ป๐ฐ๐ผ๐ฑ๐ถ๐ป๐ด ๐๐ผ๐ฟ ๐๐ฒ๐๐ฒ๐น๐ผ๐ฝ๐ฒ๐ฟ๐
You use Base64 in CSS and JWT tokens. You need to know how it works.
Base64 turns binary data into a text string. It uses a 64 character set. This includes A-Z, a-z, 0-9, +, and /. The = sign handles padding.
Base64 is encoding. It is not encryption. Never use it for security.
How it works:
- Split binary data into 3 byte groups.
- Divide these into four 6 bit chunks.
- Map each chunk to a character.
Common uses:
- Email attachments.
- Images in HTML and CSS.
- JWT tokens.
- API responses.
- Basic Auth headers.
Coding examples: Use btoa to encode strings. Use atob to decode strings. In Node.js, use data.toString('base64').
Base64url is a special version for URLs. It replaces + with - and / with _. It removes padding. Use this for JWTs.
Keep these facts in mind:
- Output is 33% larger than the original.
- Use it for text only channels.
- Use Base64url for URLs.
Source: https://dev.to/moksh/base64-encoding-explained-a-practical-guide-for-developers-49hh