Base64 in Go

게시

이 가이드에서

This developer guide on Base64Encoding explains go 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.

다음으로 이 비공개 도구를 써 보세요

Go’s encoding/base64 package provides four ready-made encodings and lets you define custom ones.

Variable Alphabet Padding
base64.StdEncoding + / yes
base64.RawStdEncoding + / no
base64.URLEncoding - _ yes
base64.RawURLEncoding - _ no (JWT, URLs)

Strings

package main

import (
	"encoding/base64"
	"fmt"
)

func main() {
	s := base64.StdEncoding.EncodeToString([]byte("Grüße 👋"))
	fmt.Println(s) // R3LDvMOfZSDwn5GL

	b, err := base64.StdEncoding.DecodeString(s)
	if err != nil {
		panic(err) // illegal base64 data at input byte N
	}
	fmt.Println(string(b))
}

Go strings are UTF-8, so no conversion step is needed.

Decode errors

illegal base64 data at input byte 12 gives the exact position of the problem. Typical causes: Base64URL input decoded with StdEncoding, missing padding (use the Raw variant), or a data URI prefix. The decoder ignores \r and \n but nothing else.

Strict mode

enc := base64.StdEncoding.Strict() // rejects non-zero trailing bits

Without it, QQ== and QR== both decode to A. Strict mode matters when Base64 values are compared or used as keys.

Streaming

in, _ := os.Open("big.bin")
out, _ := os.Create("big.b64")
w := base64.NewEncoder(base64.StdEncoding, out)
io.Copy(w, in)
w.Close() // flushes the final partial block and padding

Forgetting Close() silently drops the last 1–2 bytes. Decode streams with base64.NewDecoder(base64.StdEncoding, r).

Appending without allocations (Go 1.22+)

buf = base64.StdEncoding.AppendEncode(buf, data)

Check your output with the Base64 decoder.

자주 묻는 질문

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 go?

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

관련 도구 및 가이드

댓글 (0)

“Base64 in Go”에 대한 질문, 아이디어, 버그가 있으신가요? 댓글을 남기거나 도구를 평가하거나 다른 사람에게 답글을 달아 주세요.

아직 댓글이 없습니다. 첫 번째로 의견을 남겨 주세요!

댓글 남기기

이 도구 평가:
Esc
↑ ↓ 이동↵ 열기Esc 닫기