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 閉じる