-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase64-encoder-decoder.html
More file actions
302 lines (269 loc) · 15.9 KB
/
Copy pathbase64-encoder-decoder.html
File metadata and controls
302 lines (269 loc) · 15.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<!DOCTYPE html>
<html lang="en">
<head>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1981515451878575" crossorigin="anonymous"></script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fast Base64 Encoder & Decoder (Instant & Secure) - QuickDevBox</title>
<meta name="description" content="Free online Base64 Encoder & Decoder. Encode and decode text, UTF-8 strings, and files to Base64 format client-side instantly.">
<link rel="canonical" href="https://quickdevbox.com/base64-encoder-decoder">
<link rel="icon" type="image/svg+xml" href="favicon.svg">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="styles.css?v=2.2">
<!-- Complete OpenGraph & Social Preview Tags -->
<meta property="og:title" content="Fast Base64 Encoder & Decoder (Instant & Secure) - QuickDevBox">
<meta property="og:description" content="Free online Base64 Encoder & Decoder. Encode and decode text, UTF-8 strings, and files to Base64 format client-side instantly.">
<meta property="og:url" content="https://quickdevbox.com/base64-encoder-decoder">
<meta property="og:type" content="website">
<meta property="og:image" content="https://quickdevbox.com/og-image.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Fast Base64 Encoder & Decoder (Instant & Secure) - QuickDevBox">
<meta name="twitter:description" content="Free online Base64 Encoder & Decoder. Encode and decode text, UTF-8 strings, and files to Base64 format client-side instantly.">
<meta name="twitter:image" content="https://quickdevbox.com/og-image.png">
<!-- Search Robots Directive -->
<meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebApplication",
"name": "Fast Base64 Encoder & Decoder (Instant & Secure) - QuickDevBox",
"description": "Free online Base64 Encoder & Decoder. Encode and decode text, UTF-8 strings, and files to Base64 format client-side instantly.",
"url": "https://quickdevbox.com/base64-encoder-decoder",
"applicationCategory": "DeveloperApplication",
"operatingSystem": "All",
"browserRequirements": "Requires JavaScript. Requires HTML5.",
"offers": {
"@type": "Offer",
"price": "0",
"priceCurrency": "USD"
},
"author": {
"@type": "Organization",
"name": "QuickDevBox Tools",
"url": "https://quickdevbox.com"
}
}
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-E0LZHPD7SL"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-E0LZHPD7SL');
</script>
</head>
<body>
<header>
<div class="nav-container">
<a href="/" class="logo">
<img src="favicon.svg" alt="QuickDevBox Logo">
QuickDevBox<span>.com</span>
</a>
<nav class="nav-links">
<a href="/">Home</a>
<a href="/json-formatter">JSON Tools</a>
<a href="/cron-expression-generator">Cron Generator</a>
<a href="/jwt-decoder">JWT Decoder</a>
<a href="/base64-encoder-decoder" class="active">Base64</a>
<a href="mailto:support@quickdevbox.com?subject=QuickDevBox%20Feedback" class="nav-support">✉️ Support</a>
</nav>
</div>
</header>
<main>
<section class="hero" style="padding: 1.5rem 0 2rem;">
<h1>Base64 Encoder & Decoder</h1>
<p>Convert strings, special characters, and binaries into RFC 4648 compliant Base64 representations securely.</p>
</section>
<section class="tool-box">
<div class="privacy-banner">
<span>🛡️ <strong>100% Client-Side Processing:</strong> Secrets and strings are encoded locally without network requests.</span>
</div>
<div class="tool-controls">
<button class="btn btn-secondary" onclick="var ta=document.querySelector('textarea'); if(ta){ta.value='Hello, QuickDevBox Developer Tools!';} if(typeof updateCounter==='function')updateCounter();" style="font-size:0.8rem; padding:0.4rem 0.8rem; margin-left:0.5rem;">💡 Fill Sample Data</button>
<button data-ux="action-primary" class="btn" onclick="encodeBase64()">🔒 Encode to Base64</button>
<button class="btn btn-secondary" onclick="decodeBase64()">🔓 Decode from Base64</button>
<button class="btn btn-secondary" onclick="copyResult()">📋 Copy Result</button>
<button data-ux="action-clear" class="btn btn-secondary" onclick="clearAll()" style="color:var(--danger);">🗑️ Clear</button>
</div>
<!-- AdSense Responsive Slot -->
<div class="ad-slot-header"></div>
<div class="editor-wrapper">
<div>
<div class="editor-header"><span class="editor-counter" id="editor-counter" style="float:right; font-size:0.8rem; margin-right:10px;">0 chars | 0 lines</span><span style="font-size:0.75rem; color:var(--text-muted); float:right; margin-top:4px;">(Ctrl+Enter)</span> Input Text / Base64 Data</div>
<textarea data-ux="input" id="baseInput" rows="12" placeholder="Enter text to encode or Base64 string to decode..."></textarea>
</div>
<div>
<div class="editor-header"><span class="editor-counter" id="editor-counter-2" style="float:right; font-size:0.8rem; margin-right:10px;">0 chars | 0 lines</span><span style="font-size:0.75rem; color:var(--text-muted); float:right; margin-top:4px;">(Ctrl+Enter)</span> Output Result</div>
<textarea id="baseOutput" rows="12" readonly placeholder="Output string will appear here..."></textarea>
</div>
</div>
<div id="statusMsg" class="status-msg"></div>
</section>
<article class="seo-article">
<h2>Base64 Architecture: RFC 4648 Bit Splitting & URL-Safe Encoding</h2>
<p>Base64 bridges the gap between raw binary bytes and legacy 7-bit ASCII transmission channels. It converts groups of 24 input bits (3 bytes) into four 6-bit chunks, with each chunk indexing a character in a 64-symbol table.</p>
<h3>Format Specifications & Syntax Reference</h3>
<table>
<thead>
<tr><th>Specification Parameter</th><th>Standard Value / Parsing Behavior</th></tr>
</thead>
<tbody>
<tr><td><strong>Payload Overhead</strong></td><td>+33.3% size inflation (4 output chars per 3 input bytes)</td></tr>
<tr><td><strong>IETF Specification</strong></td><td>RFC 4648 §4 (Standard) & §5 (URL / Filename Safe)</td></tr>
<tr><td><strong>Standard Alphabet</strong></td><td>A-Z, a-z, 0-9, +, / (Padding: =)</td></tr>
<tr><td><strong>URL-Safe Alphabet</strong></td><td>A-Z, a-z, 0-9, -, _ (No padding in JWTs)</td></tr>
</tbody>
</table>
<div class="edge-cases-box">
<h4>⚠️ Common Engineering Edge Cases & Gotchas</h4>
<ul>
<li><strong>Why does btoa() fail with InvalidCharacterError on Unicode or Chinese characters:</strong> Browser window.btoa() expects binary strings where character codes are strictly between 0 and 255 (Latin1). Multibyte UTF-8 characters exceed this range, throwing DOMException. Convert string to UTF-8 bytes using TextEncoder before passing to btoa().</li>
<li><strong>Why does Base64 data corrupt when passed inside URL query parameters:</strong> Standard Base64 contains '+' which HTTP query string parsers decode as a literal space ('%20'). Always use RFC 4648 §5 URL-Safe Base64 (swapping '+' for '-' and '/' for '_') to prevent delimiter corruption.</li>
</ul>
</div>
<h3>Production Implementation Examples</h3>
<h4>Node.js / Modern Browser (UTF-8 Safe)</h4>
<pre><code>// Native TextEncoder prevents Latin1 InvalidCharacterError
function toBase64(text) {
const bytes = new TextEncoder().encode(text);
const bin = Array.from(bytes, b => String.fromCharCode(b)).join('');
return btoa(bin);
}
function fromBase64(b64) {
const bin = atob(b64);
const bytes = Uint8Array.from(bin, c => c.charCodeAt(0));
return new TextDecoder().decode(bytes);
}
// URL-Safe Base64 (RFC 4648 §5 - used in JWT headers and OAuth 2.0 PKCE)
function toBase64Url(text) {
return toBase64(text).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
}</code></pre>
<h4>Python 3</h4>
<pre><code>import base64
raw_bytes = "Hello UTF-8 🚀".encode("utf-8")
std_b64 = base64.b64encode(raw_bytes).decode("ascii")
# URL-Safe Base64 (swaps '+' for '-', '/' for '_', strips padding)
url_b64 = base64.urlsafe_b64encode(raw_bytes).rstrip(b"=").decode("ascii")
# Safe decoding with automatic padding restoration
padding_needed = (4 - len(url_b64) % 4) % 4
decoded = base64.urlsafe_b64decode(url_b64 + "=" * padding_needed).decode("utf-8")</code></pre>
<h3>High-Throughput Processing & Memory Safety Bounds</h3>
<p>Client-side parsing and data transformation operates against browser V8 memory limits. When manipulating large documents or high-volume datasets approaching the 2MB boundary, synchronous operations can block the main execution thread. Production web applications should delegate heavy serialization and formatting jobs to background Web Workers or leverage streaming parsers (such as the WHATWG <code>TransformStream</code> interface) to maintain interface responsiveness during heavy data ingestion. Ensure robust UTF-8 multi-byte sequence validation to prevent surrogate pair slicing and payload corruption. Incorporate automated benchmark assertions into build pipelines to intercept algorithmic complexity regressions before production release.</p>
<h3>Official Standards & Format Specifications</h3>
<ul>
<li><a href="https://datatracker.ietf.org/doc/html/rfc4648" target="_blank" rel="noopener noreferrer">RFC 4648: The Base16, Base32, and Base64 Data Encodings</a></li>
<li><a href="https://html.spec.whatwg.org/multipage/webappapis.html#atob" target="_blank" rel="noopener noreferrer">WHATWG HTML Living Standard: Base64 utility methods</a></li>
</ul>
</article>
<section class="related-tools" style="margin-top:3rem; padding-top:2rem; border-top:1px solid var(--bg-card-border);">
<h3 style="font-size:1.2rem; margin-bottom:1rem; color:var(--text-bright);">🔗 Related Developer Tools</h3>
<div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:1rem;">
<a href="/json-formatter" class="tool-card" style="padding:1rem; text-decoration:none;">
<div style="font-weight:600; color:var(--primary-light); margin-bottom:0.25rem;">JSON Formatter</div>
<div style="font-size:0.8rem; color:var(--text-muted);">Format & Validate JSON</div>
</a>
<a href="/jwt-decoder" class="tool-card" style="padding:1rem; text-decoration:none;">
<div style="font-weight:600; color:var(--primary-light); margin-bottom:0.25rem;">JWT Decoder</div>
<div style="font-size:0.8rem; color:var(--text-muted);">Decode & Debug JWT Tokens</div>
</a>
<a href="/hash-generator" class="tool-card" style="padding:1rem; text-decoration:none;">
<div style="font-weight:600; color:var(--primary-light); margin-bottom:0.25rem;">Hash Generator</div>
<div style="font-size:0.8rem; color:var(--text-muted);">SHA-256 / SHA-512 Hashes</div>
</a>
<a href="/diff-checker" class="tool-card" style="padding:1rem; text-decoration:none;">
<div style="font-weight:600; color:var(--primary-light); margin-bottom:0.25rem;">Diff Checker</div>
<div style="font-size:0.8rem; color:var(--text-muted);">Compare Text Differences</div>
</a>
</div>
</section>
</main>
<footer>
<div class="footer-container" style="max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; text-align: center; color: var(--text-muted); font-size: 0.85rem; border-top: 1px solid var(--bg-card-border);">
<p>© 2026 QuickDevBox.com — Free, Open Source & Privacy-First Developer Tools</p>
<p style="margin-top: 0.5rem;">
<a href="/privacy-policy" style="color: var(--text-muted); text-decoration: none; margin: 0 0.5rem;">Privacy Policy</a> |
<a href="/terms" style="color: var(--text-muted); text-decoration: none; margin: 0 0.5rem;">Terms of Service</a> |
<a href="/about" style="color: var(--text-muted); text-decoration: none; margin: 0 0.5rem;">About</a> |
<a href="https://github.com/hbx1982/quickdevbox" target="_blank" rel="noopener noreferrer" style="color: var(--text-muted); text-decoration: none; margin: 0 0.5rem;">GitHub</a> |
<a href="mailto:support@quickdevbox.com?subject=QuickDevBox%20Feedback" style="color: var(--text-muted); text-decoration: none; margin: 0 0.5rem;">Contact Support</a>
</p>
</div>
</footer>
<script>
function showStatus(msg, isError = false) {
const el = document.getElementById('statusMsg');
el.style.display = 'block';
el.className = 'status-msg ' + (isError ? 'status-error' : 'status-success');
el.innerText = msg;
}
function encodeBase64() {
const input = document.getElementById('baseInput').value;
if (!input) {
showStatus("Please enter input text to encode.", true);
return;
}
try {
const encoded = btoa(unescape(encodeURIComponent(input)));
document.getElementById('baseOutput').value = encoded;
showStatus("Text successfully encoded to Base64!");
} catch (err) {
showStatus("Encoding failed: " + err.message, true);
}
}
function decodeBase64() {
const input = document.getElementById('baseInput').value.trim();
if (!input) {
showStatus("Please enter Base64 string to decode.", true);
return;
}
try {
const decoded = decodeURIComponent(escape(atob(input)));
document.getElementById('baseOutput').value = decoded;
showStatus("Base64 string successfully decoded!");
} catch (err) {
showStatus("Invalid Base64 string. Unable to decode.", true);
}
}
function copyResult() {
const output = document.getElementById('baseOutput').value;
if (!output) {
showStatus("Nothing to copy!", true);
return;
}
navigator.clipboard.writeText(output);
showStatus("Copied to clipboard!");
}
function clearAll() {
document.getElementById('baseInput').value = "";
document.getElementById('baseOutput').value = "";
document.getElementById('statusMsg').style.display = 'none';
}
// Keyboard Shortcuts Support
document.addEventListener('keydown', function(e) {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
e.preventDefault();
const primaryBtn = document.querySelector('[data-ux="action-primary"], .btn-primary, button[onclick^="process"], button[onclick^="generate"], button[onclick^="analyze"]');
if (primaryBtn) primaryBtn.click();
}
});
// Large File Safeguard
document.querySelectorAll('textarea').forEach(ta => {
ta.addEventListener('input', function(e) {
if (e.target.value.length > 2 * 1024 * 1024) {
if (typeof showStatus === 'function') {
showStatus("Input exceeds 2MB limit. To protect your browser from freezing, please use a smaller payload.", true);
} else {
alert("Input exceeds 2MB limit!");
}
e.target.value = e.target.value.substring(0, 2 * 1024 * 1024);
if (typeof updateCounter === 'function') updateCounter();
}
});
});
</script>
<script src="ux-enhancements.js?v=2.2"></script>
</body>
</html>