Base64 Encode and Decode using Go

encoding/base64 package

package main

import (
    "encoding/base64"
    "fmt"
)

func main() {
    text := "Hello"
    base64Str := base64.StdEncoding.EncodeToString([]byte(text))
    fmt.Println(base64Str)

    raw, _ := base64.StdEncoding.DecodeString(base64Str)
    text = string(raw)
    fmt.Println(text)
}

Leave a Comment

Cancel reply

Your email address will not be published.