Base64 is a way of encoding binary data (like images, files, or even plain text) into a text format using only 64 characters that are safe for transmission over text-based systems (like email, URLs, JSON, etc.).
🔢 Base64 Basics
-
It uses A–Z, a–z, 0–9, +, / — 64 characters in total.
-
Encodes binary data into ASCII strings.
-
Often ends with
=padding for alignment.
📦 Why Use Base64?
| Use Case | Reason |
|---|---|
| Embedding images in HTML/JSON | Can’t embed raw binary data |
| Sending files via API | Safer to transmit as text |
| Email attachments (MIME) | Email systems are text-only |
| JWT tokens (Base64 parts) | Secure token format |
📘 Example
Original Text:
Hello
Base64 Encoded:
SGVsbG8=
Try decoding it here: https://www.base64decode.org/
🧪 In Java (Spring Boot):
Encode:
String original = "Hello";
String encoded = Base64.getEncoder().encodeToString(original.getBytes());
System.out.println(encoded); // SGVsbG8=Decode:
byte[] decodedBytes = Base64.getDecoder().decode(encoded);
String decoded = new String(decodedBytes);
System.out.println(decoded); // Hello⚠️ Important Notes
-
Base64 increases size: The output is about 33% larger than the original data.
-
Not encryption: It’s just encoding — anyone can decode it.
-
Often used in JWT headers, image uploads, and email content.
Let me know if you’re planning to use it for something specific (like sending images, JWT, or file uploads) — I can tailor the example for that!