Base64 Encoding
// Importing necessary packages.
import (
b64 "encoding/base64"
"fmt"
)
// The main function, where the execution of the program begins.
func main() {
// The data to be encoded.
data := "abc123!?$*&()'-=@~"
// Standard Encoding
// Encoding the data using standard base64 encoding.
sEnc := b64.StdEncoding.EncodeToString([]byte(data))
fmt.Println(sEnc)
// Decoding the base64-encoded string back to the original data.
sDec, _ := b64.StdEncoding.DecodeString(sEnc)
fmt.Println(string(sDec))
fmt.Println()
// URL Encoding
// Encoding the data using URL-compatible base64 encoding.
uEnc := b64.URLEncoding.EncodeToString([]byte(data))
fmt.Println(uEnc)
// Decoding the URL-encoded base64 string back to the original data.
uDec, _ := b64.URLEncoding.DecodeString(uEnc)
fmt.Println(string(uDec))
}Output
Last updated