Common Use Cases

Kubernetes Secrets

Base64 encoding is used in Kubernetes secrets to store sensitive data:

apiVersion: v1
kind: Secret
metadata:
  name: my-secret
type: Opaque
data:
  password: cGFzc3dvcmQxMjM= # base64 encoded

Cloud-Init User Data

Base64 encoding is commonly used in cloud-init scripts:

#cloud-config
write_files:
- encoding: base64
  content: IyEvYmluL2Jhc2gK
  path: /script.sh

Data URIs

Base64 is used in data URIs to embed images and other files directly in HTML/CSS:

<img src="data:image/png;base64,iVBORw0K..." />

Email Attachments

MIME uses Base64 to encode email attachments and non-text content:

Content-Type: image/jpeg
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRg...

Warning

While its in somecase it used to encode sensitive information it is not a secure method of encryption.

Command Line Usage

Linux/macOS

Encode a string:

echo -n "Hello World" | base64

Decode a string:

echo "SGVsbG8gV29ybGQ=" | base64 -d

Encode a file:

base64 file.txt encoded.txt

Windows PowerShell

Encode a string:

[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("Hello World"))

Decode a string:

[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("SGVsbG8gV29ybGQ="))

Encode a file:

[Convert]::ToBase64String([IO.File]::ReadAllBytes("file.txt"))