logo
GeekFormat

Base64 編碼

輸入文字
0 字元

免費線上 Base64 編碼解碼工具,支援 UTF-8/ASCII/ISO-8859-1,Standard/URL-Safe/MIME 三種變體,即時體積統計,MIME 76字元符合 RFC 2045。

相關推薦

適用場景

  • JWT debugging
  • HTTP Basic Auth encoding
  • OAuth PKCE generation
  • API debugging
  • Data URI image embedding
  • Email attachment encoding

功能特點

  • Encode/Decode toggle with circular processing
  • UTF-8/ASCII/ISO-8859-1 charset support
  • Standard/URL-Safe/MIME variants
  • Real-time size statistics
  • Friendly error messages
  • Draggable divider on desktop
  • Mobile tab switching

使用方法

  1. Select Encode or Decode mode
  2. Choose variant (Standard/URL-Safe/MIME)
  3. Paste content for real-time processing
  4. View statistics at bottom
  5. Copy result with one click

常見問題

Is Base64 the same as encryption?

No. Base64 is a reversible encoding anyone can decode. For sensitive data use AES. Base64 only converts data format for text-safe transmission.

AES Encryption

How much size increase does Base64 cause?

Approximately 33%. Every 3 bytes become 4 characters. Example: Hello → SGVsbG8= (+33%).

Standard vs URL-Safe vs MIME?

Standard uses +/; URL-Safe replaces with -_ for URLs/JWT; MIME wraps at 76 chars per RFC 2045 for email.

URL-SafeMIME

How to decode JWT payload?

JWT uses Base64URL. Select URL-Safe mode and paste the second segment.

JWT Tool

What is Base64 Padding?

= characters added when input is not a multiple of 3 bytes, making output length a multiple of 4.

Padding Tool

Why does btoa fail on Chinese?

btoa/atob only support Latin-1 (1 byte per char). Use encodeURIComponent + unescape for UTF-8 strings.

What is Data URI?

Format: data:[mediatype][;base64],<data>. Embeds files directly in URLs for reduced HTTP requests.

Data URIBase64 to Image

什麼是Base64 編碼?

Base64 是基於 64 個可列印 ASCII 字元的二進位到文字編碼,由 RFC 2045/4648 定義。

Base64 不是加密,只是可逆的格式轉換,用於 HTTP Basic Auth、JWT、Data URI、MIME 郵件等。

URL-Safe 變體將 +/ 替換為 -_,省略 padding,用於 URL 和 JSON 欄位。

MIME 變體每行 76 字元,用於電子郵件。

使用瀏覽器原生 API,所有計算在本機完成。

术语表

RFC 4648
IETF standard for Base16/Base32/Base64 defining alphabets and rules.URL-SafePadding
RFC 2045 (MIME)
MIME standard defining Base64 for email with 76-char line limit.MIME Base64
Base64URL
URL-safe variant replacing +/ with -_ and omitting padding.URL-SafeJWT
Padding
= characters ensuring output length is multiple of 4.Padding Tool
btoa/atob
Native browser Base64 APIs (Latin-1 only).
Data URI
URI scheme for embedding files inline: data:[type][;base64],data.Data URI
HTTP Basic Auth
Authentication encoding username:password in Base64.Auth Builder
Base64 Overhead
~33% size increase (3 bytes → 4 characters).
Base64 Alphabet
64 chars: A-Z, a-z, 0-9, +, / plus = padding.
MIME Base64
RFC 2045 variant with 76-char lines for email.MIME

Base64 Variant Comparison

FeatureStandardURL-SafeMIME
Special chars+ /- _+ /
Padding (=)UsedOmittedUsed
Line breaksNoneNoneEvery 76 chars
StandardRFC 4648 §4RFC 4648 §5RFC 2045
Use casesData URI, generalJWT, URL, filenamesEmail, SMTP

Base Series Encoding Comparison

EncodingCharsCharsetOverheadUse Case
Base16 (Hex)160-9, A-F100%Debugging, hashes
Base3232A-Z, 2-760%DNS, TOTP, QR
Base5858No 0/O/I/l38%Bitcoin, crypto
Base6262A-Z,a-z,0-934%URL shorteners
Base6464A-Z,a-z,0-9,+,/33%Data URI, MIME, JWT

Code Examples

JavaScript Base64 Encoding (UTF-8 Support)

// UTF-8 safe Base64 encode
function b64Encode(str) {
  return btoa(unescape(encodeURIComponent(str)));
}
function b64Decode(str) {
  return decodeURIComponent(escape(atob(str)));
}
function b64UrlEncode(str) {
  return btoa(unescape(encodeURIComponent(str)))
    .replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
}
console.log(b64Encode('Hello World'));

Base64 Encoding in Python

import base64
encoded = base64.b64encode('Hello World'.encode('utf-8'))
print(encoded.decode())
decoded = base64.b64decode(encoded).decode('utf-8')
print(decoded)
url_safe = base64.urlsafe_b64encode('Hello World'.encode('utf-8'))
print(url_safe.decode().rstrip('='))

Base64 Encoding in Java

import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class Base64Example {
  public static void main(String[] args) {
    String text = "Hello World";
    String encoded = Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.UTF_8));
    System.out.println(encoded);
    String decoded = new String(Base64.getDecoder().decode(encoded), StandardCharsets.UTF_8);
    System.out.println(decoded);
    String urlSafe = Base64.getUrlEncoder().withoutPadding().encodeToString(text.getBytes(StandardCharsets.UTF_8));
  }
}

Authoritative References