Method of encryption and decryption in go language base64


This article illustrates the encryption and decryption methods of go language base64. Share with you for your reference. The specific implementation method is as follows:

package main
import (
    "encoding/base64"
    "fmt"
)
const (
    base64Table = "123QRSTUabcdVWXYZHijKLAWDCABDstEFGuvwxyzGHIJklmnopqr234560178912"
)
var coder = base64.NewEncoding(base64Table)
func base64Encode(src []byte) []byte {
    return []byte(coder.EncodeToString(src))
}
func base64Decode(src []byte) ([]byte, error) {
    return coder.DecodeString(string(src))
}
func main() {
    // encode 
    hello := "hello world"
    debyte := base64Encode([]byte(hello))
    // decode 
    enbyte, err := base64Decode(debyte)
    if err != nil {
        fmt.Println(err.Error())
    }
    if hello != string(enbyte) {
        fmt.Println("hello is not equal to enbyte")
    }
    fmt.Println(string(enbyte))
}

I hope this article has been helpful to your programming of Go language.