Find out how to Base64 Encode/Decode in Golang

0
9
Adv1


Adv2

Go ships with an encoding/base64 package deal that permits for encode and decoding of Base64 strings.

Import the base64 package deal after which begin utilizing it!

Base64 encode/decode a string

package deal most important

import (
	b64 "encoding/base64"
	"fmt"
)

func most important() {
	// outline a string
	information := "It is a take a look at string!"

	// Encode to Base64
	sEnc := b64.StdEncoding.EncodeToString([]byte(information))
	fmt.Println(sEnc)

	// Decode from Base64
	sDec, _ := b64.StdEncoding.DecodeString(sEnc)
	fmt.Println(string(sDec))

	// URL Encode
	uEnc := b64.URLEncoding.EncodeToString([]byte(information))
	fmt.Println(uEnc)

	// URL Decode
	uDec, _ := b64.URLEncoding.DecodeString(uEnc)
	fmt.Println(string(uDec))
}
Adv3