Standard Base64 Encoding
Import the package with an alias to save space:Encoding
The encoder requires a[]byte, so convert your string:
Decoding
Decoding may return an error if the input is malformed:URL-Compatible Base64
For URL-safe encoding, useURLEncoding:
URL encoding uses
- and _ instead of + and / to avoid URL encoding issues.Encoding Types
StdEncoding - Standard Base64
StdEncoding - Standard Base64
Uses
+ and / characters, suitable for most usesURLEncoding - URL-safe Base64
URLEncoding - URL-safe Base64
Uses
- and _ characters, safe for URLs and filenamesRawStdEncoding - No padding
RawStdEncoding - No padding
Standard encoding without padding
= charactersRawURLEncoding - No padding, URL-safe
RawURLEncoding - No padding, URL-safe
URL encoding without padding
= charactersEncoding Functions
Encodes bytes to a Base64 string
Decodes a Base64 string to bytes
Encodes bytes to Base64 bytes
Decodes Base64 bytes to bytes
Working with Readers and Writers
For streaming operations, use encoders and decoders:Use Cases
Binary Data
Embed binary data in text formats
APIs
Transfer binary data in JSON/XML
Encode attachments in MIME
Data URIs
Embed images in HTML/CSS