Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / Go语言/Golang实现base64加密解密

Go语言/Golang实现base64加密解密package mainimport (
 "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语言包 http://www.linuxidc.com/Linux/2013-05/85171.htm《Go语言编程》高清完整版电子书 http://www.linuxidc.com/Linux/2013-05/84709.htmGo语言并行之美 -- 超越 “Hello World” http://www.linuxidc.com/Linux/2013-05/83697.htm我为什么喜欢Go语言 http://www.linuxidc.com/Linux/2013-05/84060.htmGo语言内存分配器的实现 http://www.linuxidc.com/Linux/2014-01/94766.htmGo语言的国际化支持(基于gettext-go) http://www.linuxidc.com/Linux/2014-01/94917.htm本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-06/103843.htm