设为首页 加入收藏

TOP

Go语言/Golang实现base64加密解密
2014-11-23 22:10:14 来源: 作者: 【 】 浏览:21
Tags:语言 /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))
}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android实现翻页功能原理【附源码.. 下一篇Go语言产生素数

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: