Browse Source

long2short

marion 4 years ago
parent
commit
a616bd3653
1 changed files with 41 additions and 0 deletions
  1. 41 0
      base64.go

+ 41 - 0
base64.go

@@ -0,0 +1,41 @@
+package main
+
+import (
+	"encoding/base64"
+	"fmt"
+	"log"
+)
+
+func main() {
+	str := "W3RpOuahpei+ueWnkeWomF0KW2FyOk1D5rW35LymXQpbYWw65qGl6L655aeR5aiYXQpbYnk6bWVuZ3hpbl9rYXJha2FsXQpbb2Zmc2V0OjBdClswMDowMC4wMF3moaXovrnlp5HlqJggLSDmtbfkvKYKWzAwOjAzLjQzXeivje+8mua1t+S8pgpbMDA6MDYuODdd5puy77ya5rW35LymClswMDoxMC4zMV3nvJbmm7LvvJrmvKDlv4Pol6QKWzAwOjEzLjc0Xeinhuinie+8muWNjueOrui9qQpbMDA6MTcuMThd5pqW6Ziz5LiLIOaIkei/juiKrOiKsyDmmK/osIHlrrbnmoTlp5HlqJgKWzAwOjIyLjM0XQpbMDA6MjMuMTld5oiR6LWw5Zyo5LqG6YKj5bqn5bCP5qGl5LiKClswMDoyNi4yOF3kvaDmiprnkLTlpY/lv6fkvKQKWzAwOjI4LjMzXQpbMDA6MjkuNjFd5qGl6L655q2M5ZSx55qE5bCP5aeR5aiYIOS9oOecvOinkuWcqOa1gea3jApbMDA6MzQuNjBdClswMDozNS43N13kvaDor7TkuIDkuKrkurrlnKjpgJ7lvLog5LiA5Liq5Lq65b+15a625LmhClswMDo0MC45M10KWzAwOjQyLjA3XemjjuWNjuaooeagtyDkvaDokL3okL3lpKfmlrkKWzAwOjQ3LjI3XQpbMDA6NDguMjRd5Z2Q5Zyo5qGl5LiKIOaIkeWQrOS9oOatjOWUsQpbMDA6NTMuODNdClswMDo1Ni43Nl3miJHor7TmoaXovrnlp5HlqJgg5L2g55qE6Iqs6IqzClswMTowMi42Nl0KWzAxOjAzLjc4XeaIkeaKiuS9oOaUvuW/g+S4iiDliLvlnKjkuobmiJHlv4PohpsKWzAxOjA4Ljg3XQpbMDE6MDkuOTdd5qGl6L655aeR5aiYIOS9oOeahOW/p+S8pApbMDE6MTUuMDddClswMToxNi4yMV3miJHmiorkvaDmlL7lv4PmiL8g5LiN5oOz6K6p5L2g5rWB5rWqClswMToyMS4yNF0KWzAxOjM3Ljk4XeaalumYs+S4iyDnmoTmoaXlpLTml4Eg5pyJ6L+Z5qC35LiA5aeR5aiYClswMTo0Mi45NV0KWzAxOjQzLjg0XeWlueacieedgOmVv+mVv+eahOS5jOm7keWPkSDkuIDlj4znnLzmmI7kuq4KWzAxOjQ5LjE3XQpbMDE6NTAuMjld5aeR5aiY5L2g6K6p5oiR5b+D6I2h5ry+IOWwj+m5v+WcqOS5seaSngpbMDE6NTUuNDldClswMTo1Ni40NV3kvaDor7Tml6DkurrlnKjouqvml4Eg5LiA5Liq5Lq65Zyo5rWB5rWqClswMjowMS45MF0KWzAyOjAyLjY3XemjjuWNjuaooeagtyDkvaDokL3okL3lpKfmlrkKWzAyOjA3LjkxXQpbMDI6MDguODNd5Z2Q5Zyo5qGl5LiKIOaIkeWQrOS9oOatjOWUsQpbMDI6MTQuNTBdClswMjoxNy40NV3miJHor7TmoaXovrnlp5HlqJgg5L2g55qE6Iqs6IqzClswMjoyMy4zN10KWzAyOjI0LjQ2XeaIkeaKiuS9oOaUvuW/g+S4iiDliLvlnKjkuobmiJHlv4PohpsKWzAyOjI5LjY2XQpbMDI6MzAuNjhd5qGl6L655aeR5aiYIOS9oOeahOW/p+S8pApbMDI6MzUuNzBdClswMjozNi43OV3miJHmiorkvaDmlL7lv4PmiL8g5LiN5oOz6K6p5L2g5rWB5rWq"
+	decodeBytes, err := base64.StdEncoding.DecodeString(str)
+	if err != nil {
+		log.Fatalln(err)
+	}
+	fmt.Println(string(decodeBytes))
+
+	//input := []byte("hello world")
+	//
+	//// 演示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))
+}