library: encoding/base32
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/base32"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
func base64Demo() {
|
||||
msg := "Hello, 世界"
|
||||
encoded := base64.StdEncoding.EncodeToString([]byte(msg))
|
||||
fmt.Println(encoded)
|
||||
@@ -16,3 +17,20 @@ func main() {
|
||||
}
|
||||
fmt.Println(string(decoded))
|
||||
}
|
||||
|
||||
func base32Demo() {
|
||||
str := "JBSWY3DPFQQHO33SNRSCC==="
|
||||
dst := make([]byte, base32.StdEncoding.DecodedLen(len(str)))
|
||||
n, err := base32.StdEncoding.Decode(dst, []byte(str))
|
||||
if err != nil {
|
||||
fmt.Println("decode error:", err)
|
||||
return
|
||||
}
|
||||
dst = dst[:n]
|
||||
fmt.Printf("%q\n", dst)
|
||||
}
|
||||
|
||||
func main() {
|
||||
base64Demo()
|
||||
base32Demo()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user