go: base64编码解码

2020-01-20 11:54:34 浏览数 (1)

直接来代码吧:

代码语言:javascript复制
package main

import (
    "encoding/base64"
    "fmt"
)

func main() {
    src := []byte("hello")
    ret := base64.StdEncoding.EncodeToString(src)
    fmt.Println(ret) //aGVsbG8=

    src2, err := base64.StdEncoding.DecodeString(ret) // return bytes
    fmt.Println(string(src2), err)
}

0 人点赞