-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase64-encoder.html
More file actions
412 lines (391 loc) · 20.7 KB
/
base64-encoder.html
File metadata and controls
412 lines (391 loc) · 20.7 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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Base64 Encoder / Decoder - Convert Text to Base64 Online</title>
<meta name="description" content="Free online Base64 encoder and decoder tool. Convert text to Base64 format and decode Base64 strings instantly. Secure, fast, and developer-friendly.">
<link rel="canonical" href="https://binary-code-translator.com/base64-encoder.html">
<!-- Open Graph Meta Tags -->
<meta property="og:title" content="Base64 Encoder / Decoder - Convert Text to Base64 Online">
<meta property="og:description" content="Free online Base64 encoder and decoder tool. Convert text to Base64 format and decode Base64 strings instantly.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://binary-code-translator.com/base64-encoder.html">
<!-- Twitter Card Meta Tags -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Base64 Encoder / Decoder - Convert Text to Base64 Online">
<meta name="twitter:description" content="Free online Base64 encoder and decoder tool. Convert text to Base64 format and decode Base64 strings instantly.">
<!-- Structured Data -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebApplication",
"name": "Base64 Encoder / Decoder",
"description": "Free online tool to encode text to Base64 and decode Base64 to text",
"url": "https://binary-code-translator.com/base64-encoder.html",
"applicationCategory": "DeveloperApplication",
"operatingSystem": "Any",
"offers": {
"@type": "Offer",
"price": "0",
"priceCurrency": "USD"
}
}
</script>
<link rel="stylesheet" href="css/style.css">
<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@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
</head>
<body data-mode="base64">
<header>
<div class="container">
<div class="nav-wrapper">
<div class="logo">
<h1><a href="index.html">Binary Code Translator</a></h1>
<div class="tagline">Professional Base64 Encoder & Decoder - Free Online Tool</div>
</div>
<button class="mobile-menu-toggle" id="mobileMenuToggle">☰</button>
<nav>
<ul>
<li><a href="index.html">Binary Translator</a></li>
<li>
<a href="#" onclick="return false;">
Number Base Converters
<span class="dropdown-arrow"></span>
</a>
<div class="dropdown">
<div class="dropdown-item">
<div class="dropdown-category">Binary Converters</div>
<a href="binary-to-decimal.html">Binary ↔ Decimal</a>
<a href="binary-to-hex.html">Binary ↔ Hexadecimal</a>
</div>
<div class="dropdown-item">
<div class="dropdown-category">Multi-Base Converters</div>
<a href="base-converter.html">Base 2-62 Converter</a>
</div>
</div>
</li>
<li>
<a href="#" onclick="return false;" class="active">
Developer Tools
<span class="dropdown-arrow"></span>
</a>
<div class="dropdown">
<div class="dropdown-item">
<div class="dropdown-category">Encoding</div>
<a href="base64-encoder.html" class="active">Base64 Encoder/Decoder</a>
<a href="url-encoder.html">URL Encoder/Decoder</a>
</div>
</div>
</li>
<li><a href="blog/index.html">Blog</a></li>
</ul>
</nav>
</div>
</div>
</header>
<main class="container">
<section class="converter-section">
<div class="converter-box">
<div class="converter-header">
<h2>Base64 Encoder and Decoder</h2>
<div class="quick-actions">
<button id="btnHistory" class="btn btn-icon" title="View History" aria-label="View Conversion History">📜</button>
</div>
</div>
<div class="input-group">
<div class="label-container">
<label for="inputLeft">
<span class="label-icon">📝</span>
<span class="label-text">Input Text / Base64</span>
</label>
<div class="stats-container">
<span class="char-count" id="charCountLeft">0 chars</span>
<span class="word-count" id="wordCountLeft">0 words</span>
<span class="line-count" id="lineCountLeft">0 lines</span>
</div>
</div>
<div class="input-wrapper">
<textarea id="inputLeft" placeholder="Type or paste content here to encode or decode..." autofocus></textarea>
<div id="dragOverlay" class="drag-overlay">
📁 Drop file here to convert
</div>
</div>
<div class="input-actions">
<button class="btn btn-copy" data-target="inputLeft">
<span class="btn-icon">📋</span> Copy
</button>
<button class="btn btn-paste" onclick="navigator.clipboard.readText().then(text => document.getElementById('inputLeft').value = text)">
<span class="btn-icon">📥</span> Paste
</button>
<button class="btn btn-clear" onclick="document.getElementById('inputLeft').value = ''; document.getElementById('inputRight').value = '';">
<span class="btn-icon">🗑️</span> Clear
</button>
</div>
</div>
<div class="controls" style="display:flex; gap:1rem; justify-content:center; margin: 1.5rem 0;">
<button class="btn btn-primary" onclick="encodeBase64()">
<span class="btn-icon">🔒</span> Encode (Text → Base64)
</button>
<button id="btnSwap" class="btn btn-icon" title="Swap Input/Output" aria-label="Swap Input and Output" style="margin: 0 0.5rem;">⇄</button>
<button class="btn btn-primary" onclick="decodeBase64()">
<span class="btn-icon">🔓</span> Decode (Base64 → Text)
</button>
</div>
<div class="input-group">
<div class="label-container">
<label for="inputRight">
<span class="label-icon">✅</span>
<span class="label-text">Result</span>
</label>
<div class="stats-container">
<span class="char-count" id="charCountRight">0 chars</span>
<span class="word-count" id="wordCountRight">0 words</span>
<span class="line-count" id="lineCountRight">0 lines</span>
</div>
</div>
<div class="input-wrapper">
<textarea id="inputRight" readonly placeholder="Result will appear here..."></textarea>
</div>
<div class="output-actions">
<button class="btn btn-copy" data-target="inputRight">
<span class="btn-icon">📋</span> Copy Result
</button>
<button id="btnDownload" class="btn">
<span class="btn-icon">💾</span> Download
</button>
</div>
</div>
<div id="errorMsg" class="error-msg"></div>
</div>
</section>
<!-- Features Section -->
<section class="features-section collapsible-section">
<div class="section-header" data-target="features">
<h2 class="section-title">Key Features</h2>
<span class="section-toggle">▼</span>
</div>
<div class="section-content" id="features">
<div class="features-grid">
<div class="feature-card">
<div class="feature-icon">⚡</div>
<h3>Instant Conversion</h3>
<p>Encode and decode Base64 strings instantly. No waiting, no page reloads.</p>
</div>
<div class="feature-card">
<div class="feature-icon">🌍</div>
<h3>UTF-8 Support</h3>
<p>Fully supports UTF-8 characters, including emojis and non-Latin scripts.</p>
</div>
<div class="feature-card">
<div class="feature-icon">🔒</div>
<h3>Secure & Private</h3>
<p>All conversions happen locally in your browser. Your data never leaves your device.</p>
</div>
</div>
</div>
</section>
<!-- Examples Section -->
<section class="examples-section collapsible-section">
<div class="section-header" data-target="examples">
<h2 class="section-title">Base64 Encoding Examples</h2>
<span class="section-toggle">▼</span>
</div>
<div class="section-content" id="examples">
<div class="examples-grid">
<div class="example-item">
<div class="example-preview">Hello World</div>
<div class="example-code">SGVsbG8gV29ybGQ=</div>
<button class="btn btn-example" data-text="Hello World">Try it</button>
</div>
<div class="example-item">
<div class="example-preview">Base64</div>
<div class="example-code">QmFzZTY0</div>
<button class="btn btn-example" data-text="Base64">Try it</button>
</div>
<div class="example-item">
<div class="example-preview">123456789</div>
<div class="example-code">MTIzNDU2Nzg5</div>
<button class="btn btn-example" data-text="123456789">Try it</button>
</div>
<div class="example-item">
<div class="example-preview">🔒 Secure</div>
<div class="example-code">8J+UkCBTZWN1cmU=</div>
<button class="btn btn-example" data-text="🔒 Secure">Try it</button>
</div>
</div>
</div>
</section>
<!-- Educational Content -->
<section class="educational-section collapsible-section">
<div class="section-header" data-target="educational">
<h2 class="section-title">About Base64 Encoding</h2>
<span class="section-toggle">▼</span>
</div>
<div class="section-content" id="educational">
<div class="educational-content">
<div class="edu-text">
<h3>What is Base64?</h3>
<p>Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It is designed to carry data stored in binary formats across channels that only reliably support text content.</p>
<h3>Why Use Base64?</h3>
<p>Base64 is commonly used in:</p>
<ul>
<li><strong>Email Attachments:</strong> Sending binary files via email systems designed for text.</li>
<li><strong>Data URIs:</strong> Embedding small images or fonts directly into HTML/CSS.</li>
<li><strong>APIs:</strong> Transmitting binary data in JSON or XML formats.</li>
<li><strong>Authentication:</strong> Encoding credentials in HTTP headers.</li>
</ul>
<h3>How to Use This Tool</h3>
<ol>
<li><strong>To Encode:</strong> Type text into the input box and click "Encode".</li>
<li><strong>To Decode:</strong> Paste a Base64 string and click "Decode".</li>
</ol>
</div>
</div>
</div>
</section>
<!-- FAQ Section -->
<section class="faq-section collapsible-section">
<div class="section-header" data-target="faq">
<h2 class="section-title">Frequently Asked Questions</h2>
<span class="section-toggle">▼</span>
</div>
<div class="section-content" id="faq">
<div class="faq-container">
<div class="faq-item">
<div class="faq-question">
<h3>Is Base64 encryption?</h3>
<span class="faq-toggle">+</span>
</div>
<div class="faq-answer">
<p>No, Base64 is an encoding scheme, not encryption. It does not secure data; it simply changes its representation. Anyone can decode Base64 back to the original data.</p>
</div>
</div>
<div class="faq-item">
<div class="faq-question">
<h3>Does this tool handle images?</h3>
<span class="faq-toggle">+</span>
</div>
<div class="faq-answer">
<p>Currently, this tool is optimized for text strings. For images, you would typically need a file-to-Base64 converter.</p>
</div>
</div>
<div class="faq-item">
<div class="faq-question">
<h3>Why does Base64 end with =?</h3>
<span class="faq-toggle">+</span>
</div>
<div class="faq-answer">
<p>The equals sign (=) is used as padding in Base64. Base64 encodes data in groups of 3 bytes (24 bits) into 4 characters. If the input data isn't a multiple of 3 bytes, padding is added to make the output a multiple of 4 characters.</p>
</div>
</div>
<div class="faq-item">
<div class="faq-question">
<h3>Can I use Base64 for passwords?</h3>
<span class="faq-toggle">+</span>
</div>
<div class="faq-answer">
<p>No! Base64 encoding is not secure for storing passwords. Use proper hashing algorithms like bcrypt, Argon2, or PBKDF2 for password storage. Base64 is easily reversible and provides no security.</p>
</div>
</div>
<div class="faq-item">
<div class="faq-question">
<h3>What characters does Base64 use?</h3>
<span class="faq-toggle">+</span>
</div>
<div class="faq-answer">
<p>Standard Base64 uses 64 characters: A-Z (uppercase), a-z (lowercase), 0-9 (digits), + (plus), and / (slash). The character = is used for padding. There are also URL-safe variants that replace + and / with - and _.</p>
</div>
</div>
</div>
</div>
</section>
</main>
<!-- History Modal -->
<div id="historyModal" class="modal" style="display: none;">
<div class="modal-content">
<div class="modal-header">
<h2>Conversion History</h2>
<div class="modal-header-actions">
<button id="clearHistory" class="btn btn-danger btn-sm">Clear History</button>
<button class="modal-close" id="closeHistory">×</button>
</div>
</div>
<div class="modal-body">
<div id="historyList" class="history-list">
<p class="no-history">No conversion history yet</p>
</div>
</div>
</div>
</div>
<footer>
<div class="container">
<div class="footer-content">
<div class="footer-section">
<h3>Binary Code Translator</h3>
<p>Free online tool to translate text to binary and binary to text. Fast, secure, and easy to use.</p>
</div>
<div class="footer-section">
<h4>Tools</h4>
<ul>
<li><a href="index.html">Binary Translator</a></li>
<li><a href="binary-to-decimal.html">Binary to Decimal</a></li>
<li><a href="binary-to-hex.html">Binary to Hex</a></li>
<li><a href="base64-encoder.html">Base64 Encoder</a></li>
</ul>
</div>
<div class="footer-section">
<h4>Legal</h4>
<ul>
<li><a href="legal/privacy.html">Privacy Policy</a></li>
<li><a href="legal/terms.html">Terms of Service</a></li>
</ul>
</div>
</div>
<div class="footer-bottom">
<p>© 2025 Binary Code Translator. All rights reserved.</p>
</div>
</div>
</footer>
<!-- Reusing UI controller for collapsible sections and copy functionality -->
<script src="js/ui-controller.js"></script>
<script src="js/enhanced-ui.js"></script>
<script>
// Define Converter object for UIController to use
window.Converter = {
detectInputType: function(input) {
if (!input) return 'empty';
// Simple heuristic: If it contains '=' padding, assume Base64.
// Otherwise default to text (Encode) for better typing experience.
if (input.includes('=')) return 'base64';
return 'text';
},
textToBase64: function(input) {
try {
return btoa(unescape(encodeURIComponent(input)));
} catch (e) { return "Error: Unable to encode"; }
},
base64ToText: function(input) {
try {
return decodeURIComponent(escape(window.atob(input)));
} catch (e) { return "Error: Invalid Base64 string"; }
}
};
// Manual button functions
function encodeBase64() {
const input = document.getElementById('inputLeft').value;
if (!input) return;
const result = Converter.textToBase64(input);
document.getElementById('inputRight').value = result;
// Trigger UI update manually if needed, though UIController handles input events
}
function decodeBase64() {
const input = document.getElementById('inputLeft').value;
if (!input) return;
const result = Converter.base64ToText(input);
document.getElementById('inputRight').value = result;
}
</script>
</body>
</html>