Base64 for developers

Опубликовано

В этом руководстве

This developer guide on Base64Encoding explains developers in plain language for developers and everyday users.

Everything important stays private: try the matching converter or tool in your browser — files and tokens are not uploaded.

Read the full English article below for code samples and edge cases, or switch language anytime from the menu. We keep expanding translations from real user feedback.

Затем попробуйте эти приватные инструменты

Every mainstream language ships a Base64 implementation, but they differ in the details that cause bugs: Unicode handling, URL-safe alphabets, padding, line breaks and strictness. These guides show the idiomatic way to do it in each language, and the traps to avoid.

Quick reference

Language Encode Decode
JavaScript (browser) btoa(binary) / Uint8Array.prototype.toBase64() atob(b64) / Uint8Array.fromBase64()
Node.js Buffer.from(data).toString('base64') Buffer.from(b64, 'base64')
Python base64.b64encode(data) base64.b64decode(b64)
PHP base64_encode($data) base64_decode($b64, true)
Java Base64.getEncoder().encodeToString(bytes) Base64.getDecoder().decode(b64)
C# Convert.ToBase64String(bytes) Convert.FromBase64String(b64)
Go base64.StdEncoding.EncodeToString(b) base64.StdEncoding.DecodeString(s)
Bash base64 -w0 file base64 -d file

Three rules that prevent most Base64 bugs

  1. Base64 encodes bytes, not text. Convert strings to bytes with an explicit character set (almost always UTF-8) before encoding, and back after decoding.
  2. Know your alphabet. URLs, JWTs and file names use Base64URL (- and _, usually no padding). Standard decoders reject it.
  3. Be strict when validating, lenient when reading. Reject malformed input from APIs, but strip whitespace and data URI prefixes when users paste values.

Guides by topic

Choose a language or topic below.

JavaScript How to encode and decode Base64 in JavaScript: btoa and atob, Unicode-safe UTF-8 conversion, Uint8Array.toBase64, Base64URL, files, images and Blob URLs. Python How to encode and decode Base64 in Python 3 with the base64 module: strings vs bytes, urlsafe_b64encode, validation, padding errors, files and images. PHP How to use base64_encode and base64_decode in PHP: strict decoding, URL-safe Base64, images as data URIs, files, chunk_split for e-mail and common pitfalls. Java Encode and decode Base64 in Java 8+ with java.util.Base64: basic, URL-safe and MIME encoders, without padding, streams, files and IllegalArgumentException. C# / .NET Encode and decode Base64 in C# and .NET: Convert.ToBase64String, FromBase64String, TryFromBase64String, Base64Url in .NET 9, UTF-8 strings, files and streams. Go Encode and decode Base64 in Go with encoding/base64: StdEncoding, URLEncoding, RawURLEncoding, streaming encoders, strict mode and common decode errors. Node.js Encode and decode Base64 in Node.js using Buffer: strings, files, images, Base64URL, streaming large files and validating input. Copy-ready examples. Bash / Linux Encode and decode Base64 on the Linux, macOS and Windows command line: the base64 command, -w0, openssl base64, certutil, files, strings and newline pitfalls. Data URI Data URIs (data URLs) explained: syntax, Base64 vs URL encoding, MIME types, browser limits, performance, security, and examples for HTML and CSS. CSS Base64 data URIs in CSS HTML Base64 data URIs in HTML

Часто задаваемые вопросы

Does this page upload my data?

No. Articles are static. Linked tools run locally in your browser unless a feature explicitly needs a network relay.

Can I request a translation or a new tool?

Yes — use the private feedback form. We prioritize what users ask for across languages.

What is the fastest way to try developers?

Open the homepage Base64 converter or the related tools linked on this page and paste a sample.

Похожие инструменты и руководства

Комментарии (0)

Есть вопросы, идеи или нашли ошибку в «Base64 for developers»? Оставьте комментарий, оцените инструмент или ответьте другим.

Комментариев пока нет. Станьте первым, кто поделится отзывом!

Оставить комментарий

Оцените инструмент:
Esc
↑ ↓ перемещение↵ открытьEsc закрыть