Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base64 #25

Open
yfhk opened this issue Dec 19, 2018 · 0 comments
Open

base64 #25

yfhk opened this issue Dec 19, 2018 · 0 comments

Comments

@yfhk
Copy link
Owner

yfhk commented Dec 19, 2018

package main

import (
"encoding/base64"
"fmt"
"log"
)

func main() {
input := []byte("hello golang base64 快乐编程http://www.01happy.com +~")

// 演示base64编码
encodeString := base64.StdEncoding.EncodeToString(input)
fmt.Println(encodeString)

// 对上面的编码结果进行base64解码
decodeBytes, err := base64.StdEncoding.DecodeString(encodeString)
if err != nil {
	log.Fatalln(err)
}
fmt.Println(string(decodeBytes))

fmt.Println()

// 如果要用在url中,需要使用URLEncoding
uEnc := base64.URLEncoding.EncodeToString([]byte(input))
fmt.Println(uEnc)

uDec, err := base64.URLEncoding.DecodeString(uEnc)
if err != nil {
	log.Fatalln(err)
}
fmt.Println(string(uDec))

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant