Base64 Encode / Decode

Copied!
Error: Invalid Base64 text.

Encode or decode text to and from Base64. Handles UTF-8 characters (accents, emojis, etc.) correctly.

Code Examples (Base64 with UTF-8)

How to safely encode and decode Base64 (handling UTF-8) in various languages.

import java.util.Base64;
import java.nio.charset.StandardCharsets;

// Available since Java 8
String originalText = "Hello World!";

// Encode
String encodedText = Base64.getEncoder()
    .encodeToString(originalText.getBytes(StandardCharsets.UTF_8));

// Decode
byte[] decodedBytes = Base64.getDecoder().decode(encodedText);
String decodedText = new String(decodedBytes, StandardCharsets.UTF_8);