Upload a file
  1. base64hub
  2. Base64 in Code

Base64 in Code

Tested snippets for encoding and decoding Base64 in 19 languages and tools, with URL-safe variants, file handling and the exact errors you will see.

JSCodeJavaScriptBase64 in browser JavaScript: why btoa fails on Unicode, the TextEncoder fix, Uint8Array.toBase64 and fromBase64, URL-safe output, files and exact error names.PYCodePythonEncode and decode Base64 in Python with the base64 module: UTF-8 strings, URL-safe without padding, files, streaming, validate=True and binascii.Error fixes.PHPCodePHPBase64 in PHP: base64_encode and base64_decode, why strict mode matters, URL-safe encoding with strtr, files, stream filters for large data and chunk_split.JAVACodeJavaBase64 in Java 8+ with java.util.Base64: UTF-8 strings, URL-safe without padding, the MIME encoder, file streams with wrap() and IllegalArgumentException fixes.C#CodeC#Base64 in C#: Convert.ToBase64String and FromBase64String, Base64Url in .NET 9, TryFromBase64String, line breaks, CryptoStream for big files, FormatException.GOCodeGo (Golang)Base64 in Go with encoding/base64: StdEncoding, URLEncoding and RawURLEncoding, streaming with NewEncoder, Strict mode, CorruptInputError and padding mistakes.NODECodeNode.jsBase64 in Node.js with Buffer: UTF-8 strings, the base64url encoding, files, streaming large files with a Transform, strict validation and the lenient decoder.SHCodeBashBase64 on the Linux and macOS command line: echo -n vs echo, base64 -w 0, -d vs -D, URL-safe with basenc or tr, files, padding, exit codes and 'invalid input'.RSCodeRustBase64 in Rust with the base64 crate Engine API (0.21+): STANDARD and URL_SAFE_NO_PAD, padding modes, files, EncoderWriter streaming and DecodeError variants.RBCodeRubyBase64 in Ruby: strict_encode64 vs encode64 newlines, urlsafe_encode64 padding: false, files, chunked encoding with pack('m0') and the Ruby 3.4 gem change.PSCodePowerShellBase64 in PowerShell with [Convert]::ToBase64String: UTF-8 vs UTF-16 strings, -EncodedCommand, files, large data, URL-safe output and FromBase64String errors.KTCodeKotlinBase64 in Kotlin with kotlin.io.encoding.Base64: UTF-8 strings, UrlSafe with PaddingOption, MIME, file streams, Android options and exact exception messages.SWIFTCodeSwiftBase64 in Swift with Foundation: base64EncodedString and Data(base64Encoded:), why decoding returns nil, URL-safe helpers, line-length options and large files.SSLCodeOpenSSLBase64 with the openssl command: encode and decode strings and files, -A for one-line output, the missing-newline trap, silent failures, hashes and random keys.CCodeCA compact, tested Base64 encoder and strict decoder in portable C99: buffer sizes, padding checks, streaming a file from stdin, URL-safe output, common bugs.C++CodeC++Base64 in C++: no std function exists, so here is a tested header-only C++17 encoder and decoder with URL-safe and no-padding modes, files and library APIs.DARTCodeDartBase64 in Dart and Flutter with dart:convert: base64Encode, base64Url, normalize() for missing padding, file streams, Image.memory and FormatException messages.SQLCodeSQLBase64 in SQL: MySQL TO_BASE64 and FROM_BASE64, PostgreSQL encode and decode, the SQL Server XML base64Binary trick, BASE64_ENCODE in 2025 and UTF-8 traps.PLCodePerlBase64 in Perl with core MIME::Base64: the newline argument, UTF-8 and 'Wide character' errors, encode_base64url, files in 57-byte chunks, lenient decoding.