Base64 Kodlayıcı

Metni veya veriyi Base64 formatında kodlayın. Web aktarımı için ikili verileri kodlamak için mükemmel.

0 Karakter

Base64 Kodlama Nedir?

Base64, ikili verileri bir ASCII dize formatında temsil eden ikili-metin kodlama şemasıdır. E-posta veya HTTP gibi yalnızca metni destekleyen ortamlar üzerinden ikili verileri aktarmak için yaygın olarak kullanılır.

Base64 Kodlamanın Yaygın Kullanımları

  • Veri URI'ları: Veri URI'ları kullanarak resimleri ve diğer dosyaları doğrudan HTML veya CSS'ye gömmek.
  • API Aktarımı: Yalnızca metni destekleyen JSON API'ları aracılığıyla ikili veri göndermek.
  • E-posta Ekleri: MIME (Çok Amaçlı İnternet Posta Uzantıları) e-posta eklerini kodlamak için Base64 kullanır.
  • Temel Kimlik Doğrulama: HTTP Temel Kimlik Doğrulama, kimlik bilgilerini kodlamak için Base64 kullanır.
Base64 Kodlama Nasıl Çalışır?

Base64 kodlama, 64 ASCII karakterinden (A-Z, a-z, 0-9, +, /) oluşan bir set kullanarak 8 bitlik ikili verileri 6 bitlik karakterlere dönüştürür. Her 3 bayt giriş verisi 4 Base64 karakterine dönüştürülür ve bu da veri boyutunu yaklaşık %33 artırır.

  • Step 1 - Group into 3-byte blocks: The input data is divided into groups of 3 bytes (24 bits).
  • Step 2 - Split into 6-bit segments: Each 24-bit block is split into four 6-bit segments.
  • Step 3 - Map to Base64 characters: Each 6-bit value (0-63) is mapped to one of 64 ASCII characters: A-Z (values 0-25), a-z (26-51), 0-9 (52-61), + (62), / (63).
  • Step 4 - Padding: If the input length isn't divisible by 3, padding characters (=) are added to make the output length a multiple of 4.

Example: The string "cat" (ASCII: 99, 97, 116) encodes to "Y2F0". The bytes [99, 97, 116] become binary 01100011 01100001 01110100, which splits into 6-bit groups: 011000 110110 000101 110100, mapping to Y(24) 2(54) F(5) 0(52).

History and Background

Base64 kodlama, e-posta eklerini kodlamanın bir yolu olarak 1996'da RFC 2045 (MIME) ile ortaya çıktı. Base64'ten önce, e-posta ile dosya göndermek sorunluydu çünkü e-posta protokolleri 7-bit ASCII metni için tasarlanmıştı. Bugün Base64, RFC 4648 tarafından tanımlanır ve e-postanın çok ötesinde web geliştirme, API'lar ve data URI'larda kullanılır.

Base64 Kodlama Güvenli mi?

Base64 is encoding, not encryption. It provides no security and can be easily decoded by anyone. Never use Base64 alone to protect sensitive data. Learn about encoding security

Programlama Dillerinde Base64 Kodlama

Çoğu programlama dilinde Base64 kodlama için yerleşik işlevler bulunur. İşte popüler dillerdeki örnekler:

// Basic encoding
$encoded = base64_encode($data);

// Encoding UTF-8 string
$text = "Hello, 世界!";
$encoded = base64_encode($text);

// Encoding file contents
$fileData = file_get_contents('image.png');
$encoded = base64_encode($fileData);
// Browser (btoa for ASCII only)
const encoded = btoa('Hello'); // Basic ASCII

// Browser with UTF-8 support
const encoded = btoa(unescape(encodeURIComponent('Hello, 世界!')));

// Modern browsers with TextEncoder
const encoder = new TextEncoder();
const data = encoder.encode('Hello, 世界!');
const encoded = btoa(String.fromCharCode(...data));
import base64

# Encode string (automatic UTF-8)
text = "Hello, 世界!"
encoded = base64.b64encode(text.encode('utf-8')).decode('ascii')

# Encode bytes directly
data = b'\x00\x01\x02\x03'
encoded = base64.b64encode(data).decode('ascii')

# Encode file
with open('image.png', 'rb') as f:
    encoded = base64.b64encode(f.read()).decode('ascii')
import "encoding/base64"

// Basic encoding
data := []byte("Hello, 世界!")
encoded := base64.StdEncoding.EncodeToString(data)

// URL-safe encoding
encoded := base64.URLEncoding.EncodeToString(data)

// Encoding to writer (for large data)
encoder := base64.NewEncoder(base64.StdEncoding, outputWriter)
encoder.Write(data)
encoder.Close()
import java.util.Base64;
import java.nio.charset.StandardCharsets;

// Basic encoding
String text = "Hello, 世界!";
String encoded = Base64.getEncoder()
    .encodeToString(text.getBytes(StandardCharsets.UTF_8));

// URL-safe encoding
String encoded = Base64.getUrlEncoder()
    .encodeToString(text.getBytes(StandardCharsets.UTF_8));

// MIME encoding (line breaks every 76 chars)
String encoded = Base64.getMimeEncoder()
    .encodeToString(text.getBytes(StandardCharsets.UTF_8));
require 'base64'

# Basic encoding
text = "Hello, 世界!"
encoded = Base64.encode64(text)

# Strict encoding (no newlines)
encoded = Base64.strict_encode64(text)

# URL-safe encoding
encoded = Base64.urlsafe_encode64(text)
using System;
using System.Text;

// Basic encoding
string text = "Hello, 世界!";
byte[] bytes = Encoding.UTF8.GetBytes(text);
string encoded = Convert.ToBase64String(bytes);

// With line breaks (for MIME)
string encoded = Convert.ToBase64String(bytes,
    Base64FormattingOptions.InsertLineBreaks);

Related Tools

Need to decode Base64? Use our Base64 Decoder to convert Base64 strings back to original text or binary data.

Working with URLs? Try our URL Encoder to make text URL-safe.

Displaying content on web pages? Use our HTML Entity Encoder to prevent XSS attacks.