What does the Hex to Base64 Converter do?
The Hex to Base64 Converter transforms raw hexadecimal byte sequences (Base16) into standard (RFC 4648 §4) and URL-safe Base64 (base64url) representations. It handles a wide range of common developer input formats—including space-separated bytes, colons, hyphens, C/C++ style 0x prefixes, and \x escape codes—normalizing and converting the binary payload with zero external dependencies.
Core Concepts
- Hexadecimal to Binary Decoding: Hexadecimal encoding represents each byte (8 bits) as two characters from the range
0-9anda-f. When decoding, two hex characters are combined into a single byte. - Odd-Length Alignment: Hex strings with odd lengths (e.g.
fff) imply a missing nibble. The converter automatically prepends a leading zero (0fff) to maintain rigorous 8-bit byte boundaries. - URL-Safe Base64: URL-safe Base64 replaces
+with-and/with_, preventing encoding collisions when embedding binary tokens or signatures into HTTP headers, query parameters, or JWT payloads.
How to use the tool?
- Paste Hexadecimal String: Enter your hex string, Wireshark byte dump, cryptographic hash, or binary output into the editor or click Sample.
- Configure Output Options: Optionally toggle URL-Safe Mode and choose whether to strip trailing
=padding characters. - Live Convert & Export: The tool converts instantly in real time. Click Copy or Download to export the Base64 result.
Related Developer Utilities
- Base64 to Hex: Decode standard and URL-safe Base64 strings into formatted hexadecimal byte streams.
- Base64 Encoder: Encode plain UTF-8 text strings to standard and URL-safe Base64.
- Base64 Decoder: Decode Base64 payloads back to UTF-8 text or formatted JSON.
- Base64 to Base64URL: Convert standard RFC 4648 Base64 strings to URL-safe Base64 format.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/base64/hex-to-base64) for programmatic integration into CI/CD pipelines, build systems, and autonomous agent workflows.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText |
String / Object | Hexadecimal string (aliases: text, payload, data, input, value). Supports delimiters like spaces, colons, 0x, \x. |
"48656c6c6f" |
isUrlSafe |
Boolean | Whether to output URL-safe Base64 (- and _). Default is false. |
true |
preservePadding |
Boolean | Whether to keep trailing = padding when URL-safe is active. Default is true. |
false |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/base64/hex-to-base64 \
-H "Content-Type: application/json" \
-d '{ "rawText": "48 65 6c 6c 6f 20 42 6c 75 65 75 74 69 6c 73 21", "isUrlSafe": false }'Python
import requests
url = "https://blueutils.com/api/base64/hex-to-base64"
payload = {
"rawText": "48 65 6c 6c 6f 20 42 6c 75 65 75 74 69 6c 73 21",
"isUrlSafe": False
}
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\": \"48656c6c6f\", \"isUrlSafe\": false}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/base64/hex-to-base64"))
.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 Hex parsing and Base64 conversion succeeded. | true |
result |
String | Base64 encoded output string. | "SGVsbG8=" |
cleanHex |
String | Sanitized continuous hexadecimal string without delimiters. | "48656c6c6f" |
byteLength |
Number | Total parsed binary length in bytes. | 5 |
bitLength |
Number | Total parsed binary length in bits. | 40 |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"result": "SGVsbG8gQmx1ZXV0aWxzIQ==",
"cleanHex": "48656c6c6f20426c75657574696c7321",
"byteLength": 16,
"bitLength": 128,
"isUrlSafe": false,
"preservePadding": true
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Invalid Hex format: String contains non-hexadecimal characters."
}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 convert Hex to Base64?
Integrating the Hex to Base64 API into automated DevOps pipelines and cloud microservices provides essential benefits:
- Automated Signature & Digest Translation: Convert raw cryptographic SHA/HMAC hex outputs directly into Base64 format for AWS Signature Version 4 or HTTP Authorization headers.
- Optimized Token Efficiency for AI Agents: Binary conversions are notoriously error-prone when executed purely via LLM prompt reasoning. Delegating conversion to Blueutils guarantees 100% deterministic accuracy with minimum token cost.
- Microservice Integration: Process raw byte dumps from Redis, databases, or network sensors into compact Base64 strings for JSON transport across REST boundaries.
Native Usage
Perform Hexadecimal to Base64 conversions locally without external dependencies using native OS tools:
Windows (PowerShell)
# Convert Hex string to Base64 in PowerShell
$hex = "48656c6c6f"
$bytes = for ($i = 0; $i -lt $hex.Length; $i += 2) { [Convert]::ToByte($hex.Substring($i, 2), 16) }
$b64 = [Convert]::ToBase64String($bytes)
Write-Output $b64Linux / Unix (Bash)
# Convert Hex string to Base64 using xxd and base64
echo -n "48656c6c6f" | xxd -r -p | base64Python
import base64
hex_str = "48656c6c6f"
raw_bytes = bytes.fromhex(hex_str)
b64_str = base64.b64encode(raw_bytes).decode('utf-8')
print(b64_str)Java
import java.util.Base64;
import java.util.HexFormat;
public class HexBase64 {
public static void main(String[] args) {
String hex = "48656c6c6f";
byte[] bytes = HexFormat.of().parseHex(hex);
String b64 = Base64.getEncoder().encodeToString(bytes);
System.out.println(b64);
}
}