Go语言/Golang实现base64加密解密
Go语言/Golang实现base64加密解密
Go语言/Golang实现base64加密解密
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))
}
Ubuntu 安装Go语言包
《Go语言编程》高清完整版电子书
Go语言并行之美 -- 超越 “Hello World”
我为什么喜欢Go语言
Go语言内存分配器的实现
Go语言的国际化支持(基于gettext-go)
本文永久更新链接地址:
评论暂时关闭