base64.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package main
  2. import (
  3. "encoding/base64"
  4. "fmt"
  5. "log"
  6. )
  7. func main() {
  8. 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"
  9. decodeBytes, err := base64.StdEncoding.DecodeString(str)
  10. if err != nil {
  11. log.Fatalln(err)
  12. }
  13. fmt.Println(string(decodeBytes))
  14. //input := []byte("hello world")
  15. //
  16. //// 演示base64编码
  17. //encodeString := base64.StdEncoding.EncodeToString(input)
  18. //fmt.Println(encodeString)
  19. //
  20. //// 对上面的编码结果进行base64解码
  21. //decodeBytes, err := base64.StdEncoding.DecodeString(encodeString)
  22. //if err != nil {
  23. // log.Fatalln(err)
  24. //}
  25. //fmt.Println(string(decodeBytes))
  26. //
  27. //fmt.Println("///////////////////////////////")
  28. //
  29. //// 如果要用在url中,需要使用URLEncoding
  30. //uEnc := base64.URLEncoding.EncodeToString([]byte(input))
  31. //fmt.Println(uEnc)
  32. //
  33. //uDec, err := base64.URLEncoding.DecodeString(uEnc)
  34. //if err != nil {
  35. // log.Fatalln(err)
  36. //}
  37. //fmt.Println(string(uDec))
  38. }