Using encoding/base64 in Go
Package base64 implements base64 encoding as specified by RFC 4648.
package main
import (
"encoding/base64"
"fmt"
)
func main() {
msg := "Hello, 世界"
encoded := base64.StdEncoding.EncodeToString([]byte(msg))
fmt.Println(encoded)
decoded, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
fmt.Println("decode error:", err)
return
}
fmt.Println(string(decoded))
}