-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase64-encoder-decoder.html
More file actions
393 lines (348 loc) · 20 KB
/
Copy pathbase64-encoder-decoder.html
File metadata and controls
393 lines (348 loc) · 20 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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<!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>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "Why does btoa() fail with InvalidCharacterError on Unicode or Chinese characters?",
"acceptedAnswer": {
"@type": "Answer",
"text": "The browser btoa() method only accepts Latin1 (binary strings where each character is 1 byte, 0x00 to 0xFF). Multibyte UTF-8 characters exceed this range. The modern, zero-dependency fix in browsers and Node.js is to encode with TextEncoder, map bytes to a binary string, and pass that to btoa(), or use Buffer.from(str, 'utf-8').toString('base64')."
}
},
{
"@type": "Question",
"name": "Why does Base64 break when passed inside a URL query parameter, and what is RFC 4648 §5?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Standard Base64 uses '+' and '/', which are reserved URI delimiters. Query parsers and HTTP servers decode '+' into a literal space ('%20'), corrupting the payload. RFC 4648 §5 defines URL-safe Base64, which swaps '+' for '-', '/' for '_', and strips trailing '=' padding."
}
},
{
"@type": "Question",
"name": "When should you strip or restore trailing '=' padding characters?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Padding ('=') is stripped in URL-safe contexts like JWTs and OAuth tokens to prevent query string delimiter collisions. When decoding a stripped Base64 string, decoders that strictly expect 4-character boundaries need padding restored using: while (str.length % 4) str += '='."
}
},
{
"@type": "Question",
"name": "Is Base64 an encryption algorithm, and can it secure sensitive passwords?",
"acceptedAnswer": {
"@type": "Answer",
"text": "No. Base64 is an encoding format designed for transport across 7-bit ASCII systems, not encryption. Anyone can decode it instantly without a key. Never use Base64 to store passwords (use Bcrypt/Argon2) or protect secrets (use AES-256-GCM)."
}
}
]
}
</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 (such as MIME email bodies and URL query strings). 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>
<div class="tech-specs">
<div class="spec-card">
<strong>Payload Overhead</strong>
<span>+33.3% size inflation (4 output chars per 3 input bytes)</span>
</div>
<div class="spec-card">
<strong>IETF Specification</strong>
<span>RFC 4648 §4 (Standard) & §5 (URL / Filename Safe)</span>
</div>
<div class="spec-card">
<strong>Standard Alphabet</strong>
<span><code>A-Z</code>, <code>a-z</code>, <code>0-9</code>, <code>+</code>, <code>/</code> (Padding: <code>=</code>)</span>
</div>
<div class="spec-card">
<strong>URL-Safe Alphabet</strong>
<span><code>A-Z</code>, <code>a-z</code>, <code>0-9</code>, <code>-</code>, <code>_</code> (No padding in JWTs)</span>
</div>
</div>
<h3>Production Implementation Snippets</h3>
<p>Avoid custom bitwise loops in production. Use platform-audited standard libraries with explicit UTF-8 byte handling:</p>
<h4>Node.js / Modern Browser (UTF-8 Safe)</h4>
<pre><code>// Browser & Node 18+: 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
# Standard 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>
<h4>Go (Golang)</h4>
<pre><code>package main
import (
"encoding/base64"
"fmt"
)
func main() {
payload := []byte("Hello UTF-8 🚀")
// Standard RFC 4648 Base64
std := base64.StdEncoding.EncodeToString(payload)
// URL-Safe Base64 without '=' padding (standard format for JWT claims)
urlSafe := base64.RawURLEncoding.EncodeToString(payload)
fmt.Printf("Standard: %s\nURL-Safe: %s\n", std, urlSafe)
}</code></pre>
<section class="faq-section">
<h3>Troubleshooting & Practical Engineering FAQ</h3>
<div class="faq-item">
<h4>Why does btoa() fail with "InvalidCharacterError: The string contains characters outside Latin1 range"?</h4>
<p>Browser <code>window.btoa()</code> expects binary strings where each character code is strictly between 0 and 255 (ISO-8859-1 / Latin1). When passed multibyte UTF-8 characters (like emoji 🚀 or CJK glyphs), the character code exceeds 255, throwing a DOMException.</p>
<p><strong>Fix:</strong> Convert the string to UTF-8 bytes with <code>new TextEncoder().encode(str)</code> before passing it to <code>btoa()</code>, or in Node.js environments use <code>Buffer.from(str, 'utf-8').toString('base64')</code>.</p>
</div>
<div class="faq-item">
<h4>Why does Base64 data corrupt when passed in URL query parameters?</h4>
<p>Standard Base64 contains <code>+</code> and <code>/</code>. In HTTP query strings, the plus sign <code>+</code> is reserved as an alias for a space character. When web servers (such as Nginx, Apache, or Express) parse <code>?token=abc+def</code>, they decode it as <code>abc def</code>, corrupting the Base64 bitstream.</p>
<p><strong>Fix:</strong> Always use <strong>RFC 4648 §5 URL-Safe Base64</strong> (swap <code>+</code> for <code>-</code>, <code>/</code> for <code>_</code>, and strip trailing <code>=</code>) when placing Base64 in query parameters or URL paths.</p>
</div>
<div class="faq-item">
<h4>When should you strip or restore trailing '=' padding characters?</h4>
<p>Padding characters (<code>=</code>) exist so decoders know the input byte stream ended on a 1-byte or 2-byte boundary. In URL paths and JWTs, padding is stripped because the equals sign conflicts with query string key-value delimiters. When decoding with strict libraries in Python or Java that throw <code>Incorrect padding</code>, restore the padding using modulo arithmetic:</p>
<pre><code>// Restore padding in JavaScript
while (str.length % 4 !== 0) {
str += '=';
}</code></pre>
</div>
<div class="faq-item">
<h4>Is Base64 an encryption algorithm? Can I use it to hide user passwords or secrets?</h4>
<p><strong>No. Base64 provides zero confidentiality.</strong> It is a transport encoding format, not encryption. Anyone who intercepts a Base64 string can decode it instantly without a key. Passwords must be hashed using adaptive, salted algorithms like <strong>Bcrypt</strong> or <strong>Argon2id</strong>. Confidential payloads must be encrypted using authenticated ciphers like <strong>AES-256-GCM</strong>.</p>
</div>
</section>
<h3>Standards & Authoritative References</h3>
<ul>
<li><a href="https://datatracker.ietf.org/doc/html/rfc4648" target="_blank" rel="noopener noreferrer">IETF RFC 4648: The Base16, Base32, and Base64 Data Encodings</a></li>
<li><a href="https://html.spec.whatwg.org/multipage/webappapis.html#dom-btoa" target="_blank" rel="noopener noreferrer">WHATWG HTML Living Standard: Web Application APIs (atob & btoa specification)</a></li>
<li><a href="https://tools.ietf.org/html/rfc7515#section-2" target="_blank" rel="noopener noreferrer">IETF RFC 7515: JSON Web Signature (JWS) - Base64URL Encoding Definition</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>