What does the Base64 Validator do?
The Base64 Validator inspects, validates, and diagnoses Standard Base64 (RFC 4648 §4), Base64URL (RFC 4648 §5), and MIME Base64 (RFC 2045) payloads. It detects illegal non-alphabet characters, reports exact line & column coordinate errors, identifies mixed alphabets (+/ combined with -_), analyzes modulo-4 length alignment, and detects misplaced or excessive = padding.
Core Concepts
- Modulo-4 Length Constraint: Standard Base64 maps 3 binary bytes (24 bits) into 4 ASCII characters (6 bits each). Padded strings must have a total character count divisible by 4.
- The Impossible Modulo 1: A Base64 string with
length % 4 == 1is mathematically impossible. A single 6-bit Base64 character cannot represent even a single 8-bit byte. - Base64 vs Base64URL: Standard Base64 uses
+and/with trailing=padding. Base64URL replaces them with-and_and omits padding so the string can be safely placed in HTTP URLs, query parameters, and JWT tokens. - Misplaced Padding: Padding
=characters can only appear at the very end of a Base64 stream (max 2 characters). A=in the middle indicates stream corruption.
How to use the tool?
- Enter or Upload Base64: Paste your Base64 string, JWT segment, or Data URI into the editor, click Upload, or click Sample.
- Select Expected Variant & Policy: Choose Auto-Detect, Standard (+/), or Base64URL (-_), and configure whitespace rules in the master toolbar.
- Instant Real-Time Diagnostics: The validator analyzes in real time. Review validation status, error coordinates, modulo statistics, and decoded payload previews.
- Copy Fixes or Export: Copy canonical repaired Standard / Base64URL strings with one click or download the full diagnostic report as JSON.
Context-Aware Practical Workflow Guides
Debugging JWT (JSON Web Tokens)
- JWT signatures and payload segments use unpadded Base64URL (
RFC 7519). If a standard decoder throws a padding error, use this validator to inspect unpadded tokens and generate padded canonical Standard Base64 strings.
Data URI Validation
- Inspect embedded inline images (
data:image/png;base64,...) and font files to ensure no unescaped characters or corrupted byte offsets prevent browser rendering.
Related Developer Utilities
- Base64 Encoder: Encode plain text and UTF-8 strings into standard or URL-safe Base64.
- Base64 Decoder: Decode Base64 payloads into UTF-8 text or formatted JSON.
- Base64 to Base64URL Converter: Convert standard Base64 to URL-safe format.
- Base64 to Hex Converter: Convert Base64 strings into formatted hexadecimal byte streams.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/base64/validator) for programmatic Base64 validation and diagnostics.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText |
String / Object | The Base64 string or Data URI to inspect (aliases: text, payload, data, input, value). |
"SGVsbG8gV29ybGQ=" |
expectedVariant |
String | Optional variant rule: "auto", "standard", "url_safe". |
"auto" |
allowWhitespace |
Boolean | Whether to permit RFC 2045 whitespace/newlines (default: true). |
true |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/base64/validator \
-H "Content-Type: application/json" \
-d '{
"rawText": "SGVsbG8gV29ybGQ="
}'Python
import requests
url = "https://blueutils.com/api/base64/validator"
payload = {"rawText": "SGVsbG8gV29ybGQ="}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = """
{
"rawText": "SGVsbG8gV29ybGQ="
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/base64/validator"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Indicates whether the Base64 string is valid. | true |
variant |
String | Identified variant format. | "Standard Base64 (RFC 4648 §4)" |
isStandardBase64 |
Boolean | True if conforming to standard alphabet. | true |
isBase64Url |
Boolean | True if conforming to URL-safe alphabet. | false |
charStats |
Object | Length, padding, and modulo metrics. | { "cleanedLength": 16, "modulo4": 0 } |
issues |
Array | Detailed errors and warnings list. | [] |
fixes |
Object | Canonical repaired representations. | { "canonicalBase64": "..." } |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"variant": "Standard Base64 (RFC 4648 §4)",
"isStandardBase64": true,
"isBase64Url": false,
"isDataUri": false,
"dataUriMime": null,
"hasWhitespace": false,
"charStats": {
"rawLength": 16,
"cleanedLength": 16,
"paddingCount": 1,
"modulo4": 0
},
"decodedStats": {
"byteLength": 11,
"isUtf8Text": true,
"previewText": "Hello World"
},
"issues": [],
"fixes": {
"canonicalBase64": "SGVsbG8gV29ybGQ=",
"canonicalBase64Url": "SGVsbG8gV29ybGQ"
}
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Base64 input cannot be empty.",
"issues": [
{
"type": "empty_input",
"severity": "error",
"message": "Base64 string cannot be empty."
}
]
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to validate Base64?
- Pre-Ingestion Security Checks: Verify webhook payloads and authentication headers before passing them to backend deserializers.
- Prevent Decoder Crashes: Isolate corrupted bytes and modulo-1 fragments before database persistence.
- Automated Fix Generation: Convert unpadded Base64URL tokens into standard Base64 for legacy downstream decoders.
Native Usage
How to validate and test Base64 strings locally in terminal environments:
Windows (PowerShell)
# Validate and decode Base64 in PowerShell
$str = "SGVsbG8gV29ybGQ="
try {
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($str))
Write-Host "Valid Base64" -ForegroundColor Green
} catch {
Write-Host "Invalid Base64: $_" -ForegroundColor Red
}Linux / Unix (Bash)
# Validate Base64 using Linux base64 utility
echo "SGVsbG8gV29ybGQ=" | base64 --decode > /dev/null 2>&1 && echo "Valid" || echo "Invalid"Python
Using Python standard library:
import base64
def check_base64(s):
try:
# Check standard and urlsafe decoding
decoded = base64.b64decode(s, validate=True)
return True, len(decoded)
except Exception as e:
return False, str(e)
print(check_base64("SGVsbG8gV29ybGQ="))Java
Using Java standard library:
import java.util.Base64;
public class Base64Check {
public static void main(String[] args) {
String input = "SGVsbG8gV29ybGQ=";
try {
byte[] decoded = Base64.getDecoder().decode(input);
System.out.println("Valid Base64 (" + decoded.length + " bytes)");
} catch (IllegalArgumentException e) {
System.err.println("Invalid Base64: " + e.getMessage());
}
}
}